Skip to main content

Identity methods

The SDK provides methods to manage customer identity for analytics and cross-session tracking. See Identity Tracking for a conceptual overview.

identify(userId, traits?)

Associates the current visitor with a known user identity. Call this after a user logs in.
Selektable.identify('user-123', {
  name: 'John Doe',
  email: 'john@example.com',
  plan: 'premium'
});
userId
string
required
Your system’s unique user identifier.
traits
Record<string, unknown>
Optional metadata about the user (name, email, etc.).
Behavior:
  • Persists userId and traits in the browser
  • Updates the in-memory identity state
  • Sends identity update to all currently open widgets
  • Sends the identity data to the Selektable server in the background

reset()

Clears the stored identity and generates new anonymous IDs. Call this when a user logs out.
Selektable.reset();
No parameters. Behavior:
  • Generates a new visitor ID, session ID, and anonymous ID
  • Removes stored user ID and traits
  • Updates all open widgets with the new identity

getIdentity()

Returns the current identity object.
const identity = Selektable.getIdentity();
Returns:
{
  visitorId: string;      // Persistent browser ID
  sessionId: string;      // Current session ID
  anonymousId: string;    // Anonymous ID (initially same as visitorId)
  userId?: string;        // Set after identify() is called
  traits?: Record<string, unknown>;  // Set after identify() is called
}

setVisitorId(visitorId)

Manually overrides the auto-generated visitor ID.
Selektable.setVisitorId('my-tracking-id-abc');
visitorId
string
required
Custom visitor ID to use.
Behavior:
  • Overwrites the visitor ID
  • If no user is identified, also updates the anonymous ID
  • Updates the in-memory identity state
Only use this if you manage your own visitor tracking. The auto-generated IDs work for most use cases.