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.
Recommended sequence#
- Track
Logged outwith safe, non-sensitive properties. - Call
analytics.reset(). - 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.
Redirecting logout links#
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#
| Field | Required | Type | Description |
|---|---|---|---|
eventName | true | string | Event name, such as Logged out. |
properties | false | object | Safe metadata about the logout, such as its source. |
options | false | object | Context, timestamp, integration controls, or message ID. |
callback | false | function | Runs after dispatch processing. |
Do not send credentials, tokens, passwords, payment data, or raw user-entered data in event properties.
reset API#
| Field | Required | Type | Description |
|---|---|---|---|
| Arguments | false | none | reset() 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.