Skip to content

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(userId: string, traits?: Properties, options?: { token?: string }): void
kilden.identify('user_4821', { email: '[email protected]', plan: 'pro' });

Ties 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.

  • traits are applied to the person as a $set.
  • options.token sets the identity verification JWT in the same call — equivalent to calling setIdentityToken(token) first.
  • Identifying also reloads feature flags for the new distinct id.
setPersonProperties(set: Properties, setOnce?: Properties): void
kilden.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.

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(token: string | null): void

Sets (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.