Next.js — Alias
Link an alias (e.g. anonymous ID) to a user. Use this to merge anonymous events (from before login) with the identified user. Available on both client and server.Client: useSignal
Getalias from useSignal():
Client: alias(alias)
Links an alias to the current user. Sends a$create_alias event.
| Parameter | Type | Required | Description |
|---|---|---|---|
alias | string | yes | Alias to link (e.g. previous anonymous ID) |
Server: alias(distinctId, alias, sessionId?, windowId?)
Link an alias to a user from the server. PasssessionId and windowId for client correlation.
| Parameter | Type | Required | Description |
|---|---|---|---|
distinctId | string | yes | Current user identifier (e.g. after login) |
alias | string | yes | Alias to link (e.g. previous anonymous ID) |
sessionId | string | no | From x-signal-session-id header for client correlation |
windowId | string | no | From x-signal-window-id header for client correlation |
How it works
- Before login: User browses anonymously. Events are tracked with an anonymous ID.
- After login: Call
identify(userId, traits)to set the user’s identity. - Link alias: Call
alias(anonymousId)to link the anonymous ID to the identified user. - Result: All events (both anonymous and identified) are now associated with the same user profile.
See also
- Identify — identify() and reset()
- Capture — Track events
- Server tracking — Server-side patterns
