Identity methods
These are the API signatures. For when and how to use them, read Identifying users; for the trust model behind token, read Identity verification.
identify()
Section titled “identify()”identify(userId: string, traits?: Properties, options?: { token?: string }): voidTies the current anonymous visitor to your user id. Emits a $identify event carrying the anonymous id ($anon_distinct_id), which the pipeline uses to link or merge the two identities. From this call on, events carry distinct_id = userId.
traitsare applied to the person as a$set.options.tokensets the identity verification JWT in the same call — equivalent to callingsetIdentityToken(token)first.- Identifying also reloads feature flags for the new distinct id.
setPersonProperties()
Section titled “setPersonProperties()”setPersonProperties(set: Properties, setOnce?: Properties): voidkilden.setPersonProperties( { plan: 'enterprise' }, // $set: overwrites { signup_source: 'organic' }, // $set_once: only if not already set);Updates the person’s traits. set overwrites existing values; setOnce writes only keys that don’t exist yet. Events are immutable — this changes the person, never past events.
reset()
Section titled “reset()”kilden.reset();Call on logout. Generates a new anonymous id, clears the identity token and super properties, and reloads feature flags. Without it, the next user on the same browser would be linked to the previous user’s identity.
setIdentityToken()
Section titled “setIdentityToken()”setIdentityToken(token: string | null): voidSets (or clears, with null) the identity verification JWT. The token is sent with every batch as Authorization: Bearer <token> and verified server-side. Prefer passing identityToken / getIdentityToken in init options so refresh is handled for you; use this method when your app fetches tokens on its own schedule.