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.
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.
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.
Returns:

setVisitorId(visitorId)

Manually overrides the auto-generated visitor ID.
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.