Identifying Users
Manage distinct IDs, user traits, and logout resets
Default identity behavior
The SDK creates an anonymous distinctId and stores it inlocalStorage. All events use that ID until you callidentify().
identify(userId, traits?)
analytics.identify('user_123')
analytics.identify('user_123', {
email: 'jane@example.com',
plan: 'pro',
})Calling identify() updates the current distinctId and emits a$identify event with the previous ID.
setUserProperties(properties)
Use this to update traits without changing identity. It emits$set_user.
analytics.setUserProperties({
plan: 'enterprise',
renewal_date: '2026-06-01',
})reset()
Call on logout. reset() generates a new anonymous distinctId, clears the current session ID, and emits $reset.
function handleLogout() {
analytics.track('logout_clicked')
analytics.reset()
}Inspect current IDs
const distinctId = analytics.getDistinctId()
const sessionId = analytics.getSessionId()Best practices
- Use stable internal user IDs (UUID/DB IDs)
- Call
identify()once you have a verified session - Call
reset()on logout or account switch - Do not send sensitive data in traits