Docs SDK reference window.__eln API

window.__eln API Reference

Complete reference for all window.__eln commands — track, identify, and config.

window.__eln is the single entry point for all SDK interactions from your own code. It is a function that accepts a command string followed by optional arguments.

TypeScript declaration

If you are using TypeScript, add this declaration to a .d.ts file or your global types:

interface Window {
  __eln?: (
    action: 'track' | 'identify' | 'config',
    event?: string,
    data?: Record<string, unknown>
  ) => void
}

For the pre-load queue, extend the declaration:

interface ElnFunction {
  (action: 'track' | 'identify' | 'config', event?: string, data?: Record<string, unknown>): void
  q?: IArguments[]
}

interface Window {
  __eln?: ElnFunction
}

Pre-load queue pattern

Because the SDK loads asynchronously, window.__eln may not exist when your application code runs. The pre-load queue ensures calls made before the SDK is ready are queued and replayed in order once it loads.

Define the stub once, as early as possible:

window.__eln = window.__eln || function () {
  (window.__eln.q = window.__eln.q || []).push(arguments)
}

After this, every window.__eln(...) call is safe regardless of load order. The SDK replaces the stub with the real implementation on startup and drains window.__eln.q immediately.


Commands

track

Send a behavioral event to the platform. See Events Reference for the full list of event types and their payloads.

window.__eln('track', eventName, data)
ArgumentTypeRequiredDescription
eventNamestringYesEvent type (e.g. 'CART_ADD', 'PURCHASE', 'CUSTOM')
dataobjectNoEvent-specific payload

Examples:

// Minimal — just an event name
window.__eln('track', 'EXIT_INTENT')

// With payload
window.__eln('track', 'CART_ADD', {
  product_id: 'prod_abc123',
  product_name: 'Wireless Headphones',
  price: 2999,
  currency: 'INR',
  quantity: 1,
})

// Custom event
window.__eln('track', 'CUSTOM', {
  name: 'WISHLIST_ADD',
  product_id: 'prod_abc123',
})

identify

Link the current anonymous session to a known customer. Call this after a user logs in or when you have their details from a server-side session. Subsequent sessions from the same user will be associated so nudges can be personalized.

window.__eln('identify', data)
ArgumentTypeRequiredDescription
dataobjectYesUser identity fields (see below)

Identity fields:

FieldTypeRequiredDescription
user_idstringYesYour internal user or customer ID
emailstringNoCustomer email address
namestringNoCustomer display name

Example:

// After login or on a page where the user is already authenticated
window.__eln('identify', {
  user_id: 'cust_00421',
  email: '[email protected]',
  name: 'Priya Sharma',
})

Call identify before firing transactional events like PURCHASE so those events are correctly attributed to the customer.

Note: elNudge does not store the raw email or name in any tracking event payload. The values are used for nudge personalization and attribution only.


config

Update runtime configuration for the current session. Currently supports one option:

window.__eln('config', options)
ArgumentTypeRequiredDescription
optionsobjectYesConfiguration key-value pairs

Options:

KeyTypeDescription
quietbooleantrue silences the agent for this session — no nudge widget will appear. false re-enables it.

Examples:

// Silence the agent for this session (useful on checkout pages or in automated tests)
window.__eln('config', { quiet: true })

// Re-enable after the visitor passes checkout
window.__eln('config', { quiet: false })

The quiet config is per-session. It does not persist across sessions or affect other visitors. For persistent page-level suppression, use data-quiet-zones or the Quiet Zones dashboard setting instead.


Calling order within a page

You can call window.__eln in any order. The recommended sequence for a page with a logged-in user is:

// 1. Define the stub (in <head>, before the SDK script tag)
window.__eln = window.__eln || function () {
  (window.__eln.q = window.__eln.q || []).push(arguments)
}

// 2. Identify the user (as early as possible)
window.__eln('identify', {
  user_id: 'cust_00421',
  email: '[email protected]',
  name: 'Priya Sharma',
})

// 3. Fire page-specific events in response to user actions
document.getElementById('add-to-cart').addEventListener('click', () => {
  window.__eln('track', 'CART_ADD', {
    product_id: 'prod_abc123',
    product_name: 'Wireless Headphones',
    price: 2999,
    currency: 'INR',
    quantity: 1,
  })
})