Browser SDK

Logout and reset

End a browser identity safely when a user logs out.

Logout is an identity-boundary event. Record the boundary, clear the browser identity, and identify the next account only after the next login succeeds.

  1. Track Logged out with safe, non-sensitive properties.
  2. Call analytics.reset().
  3. After the next login, call analytics.identify() for the authenticated account.

Tracking logout is recommended when the event is useful for product analysis, but it is not required for every application. Track it before reset() because reset() does not send a logout event to analytics destinations.

Use trackLink when a logout control is a link that redirects or otherwise unloads the page. It delays navigation while the logout event completes or times out. Register the reset handler with the link so the current identity is cleared as part of logout before routing begins:

Bind trackLink before the logout handler: tracking starts with the current identity, then the handler resets it, and delayed navigation gives delivery time to finish. For logout actions handled entirely by application code without navigation, use regular track, then call reset() in the logout handler.

track arguments#

FieldRequiredTypeDescription
eventNametruestringEvent name, such as Logged out.
propertiesfalseobjectSafe metadata about the logout, such as its source.
optionsfalseobjectContext, timestamp, integration controls, or message ID.
callbackfalsefunctionRuns after dispatch processing.

Do not send credentials, tokens, passwords, payment data, or raw user-entered data in event properties.

reset API#

FieldRequiredTypeDescription
Argumentsfalsenonereset() takes no arguments.

reset() clears the current user ID, anonymous ID, traits, group state, and the identity stored in cookies or local storage. It also clears the related in-memory state. It does not merge, identify, or track a new identity.

Account switching#

When users switch accounts in one browser, reset the previous identity before identifying the next account:

Do not use alias for routine logout, login, or account switching. alias is for migrating or merging a known ID into another known ID; using it between separate accounts would incorrectly combine their histories. See alias for migration guidance.