identify after every successful signup and login. From that point on, events are attributed to the ID you provide — and everything the visitor did while anonymous (properties and past events) is merged into the identified record, so you keep their full history from first visit onward.
What you need to provide:
- A stable, unique user ID from your system — use your database user ID, not an email address, since emails can change
The merge of anonymous history happens once, on the first
identify call. Calling identify again for an already identified visitor does nothing, so it’s safe to call on every login.Setting record properties
You can store any properties on a user record. Useset for values that should update, and set_once for values that should never be overwritten:
client.getIdentifier('users') returns the currently persisted user ID, so you don’t need to keep track of it yourself.
Resetting on logout
Callreset when a user logs out. It disassociates future events from the identified user and starts a new anonymous session: