Resources/Developer & SDK/Identify logged-in users

Identify logged-in users

Attach a stable user ID and traits to a visitor with Spectry.identify().

By default every visitor gets an anonymous ID. When a user signs in, call identify() to attach a stable identifier and traits so their activity is unified across devices and sessions.

Spectry.identify()

Spectry.identify('user_123', {
  email: 'jane@example.com',
  name: 'Jane Doe',
  plan: 'premium',
  signup_date: '2026-01-15',
});
  • The first argument is your user ID (the same one your app uses).
  • The second is an optional traits object — arbitrary key/value pairs.
  • The call sends the anonymous ID alongside the user ID, so the visitor's earlier anonymous activity is merged into the identified profile on the backend.
  • It also writes the user ID and any scalar traits into context, so every event sent afterwards carries them and can be segmented on without you repeating them.

Traits and context are not the same thing

Both come from this one call, and it is worth knowing which is which:

  • Traits live on the user profile. They are last-write-wins — the profile shows the plan the user is on now.
  • Context is stamped onto each event as it happens. A purchase made on the free plan still reads free after the user upgrades.

That is why a segment such as "purchases made while on the pro plan" reads context rather than traits. Only scalar traits reach context; nested objects stay on the profile.

When to call it

  • Right after a user logs in or signs up.
  • On every page load for an already-authenticated user (it's safe to call repeatedly).

Traits are merged, not replaced

Each call merges what you pass into the stored traits, and the keys you send win over the stored ones. So you can update a single field without resending the rest — but a trait you once sent stays on the profile until you overwrite it; send it as an empty string to clear it.

Resetting on logout

Spectry.resetIdentity();

This clears the stored user ID and traits and generates a fresh anonymous ID, so the next person on a shared device starts as a genuinely new visitor rather than inheriting the previous one's history. Call it in your logout handler — forgetting to is the usual reason one profile accumulates several people's sessions.

Identity is stored in localStorage. Never pass passwords, tokens or other secrets as traits — traits are visible in the dashboard and included in GDPR exports.

Where it shows up

Identified users appear under People with their traits, event timeline and sessions. See identify & traits for how the dashboard side works.


Put this to work on your own site.

Heatmaps, session replays, funnels and experiments in one platform. Set it up in minutes, no credit card needed, and 5,000 sessions a month are free forever.