Trimtab

Blog / Measuring in PostHog and Stripe

PostHog identify: linking the anonymous visitor to the signed-up user

Call posthog.identify() with your database user ID at signup, login and app load, and reset() at logout. Where to put each call, and the mistakes that split users.

posthog.identify() tells PostHog that the anonymous visitor it has been tracking is a user you know. Call it with your database user ID right after signup and login, and each time the app loads for a logged-in user. Call posthog.reset() at logout. Those three calls decide whether your funnel from first visit to paying customer is one line of data or two disconnected halves.

This guide covers what identify does under the hood, where each call goes in a SaaS, which ID to pass, the mistakes that split one person into several, and how to check that it works.

What identify does

When someone first lands on your site, PostHog gives them an anonymous ID, stored locally, and captures their events under it. At that point PostHog has a visitor and no name.

When you call identify with a distinct_id, PostHog merges the anonymous person into the identified person. The identity resolution guide describes the four steps:

  1. The SDK sends an $identify event carrying both the anonymous ID and the new one.
  2. PostHog's merge pipeline links both IDs to the same person.
  3. Past events from the anonymous ID are attributed to the merged person.
  4. Future events use the new ID.

Events keep the distinct_id they were captured with. PostHog queries through the person, so insights, funnels and timelines show the merged view, but a SQL query filtered on a single distinct_id will miss part of the history.

For a growth team, this is the link between acquisition and everything after it. Without identify, the visitor who read your pricing page from a LinkedIn ad and the user who activated three days later are two people, and no funnel can connect them.

Where to call it in a SaaS

// Right after signup or login, and on app load when a session exists
posthog.identify(user.id, {
  email: user.email,
  name: user.name,
  plan: user.plan,
});

// At logout
posthog.reset();

PostHog's best practices give two moments: every time the app loads for a logged-in user, and directly after the user logs in. Signup is the first login, so it belongs in the same place. The docs add that you only need one call per session, and that repeated calls with the same data are ignored until the page reloads. In a React app, an effect that runs when the user object is known is enough.

The call must run before the events that need to be attributed. The identity resolution guide calls this the critical constraint: a feature flag evaluated or a conversion event sent before identify belongs to the anonymous person until the merge is processed, and the flag was already hashed on the wrong ID. Identify first, then fire signed_up or onboarding_started.

Reset at logout

reset() unlinks future events on that device from the user who just left. Without it, two people sharing a computer become one person in PostHog. The docs put it in bold: call reset on logout even if you do not expect users to share a computer. reset(true) also resets the device ID.

Send the same ID from the backend

Backend SDKs have no anonymous session, so there is nothing to merge. You pass the same distinct_id on every server-side capture, which is where your payment, account creation and activation events should come from (the SaaS tracking plan explains why facts belong on the server).

The string must match exactly. PostHog treats "user-456" and "USER-456" as two people, and "user-456" and "456" too. The identity resolution guide recommends one helper in your backend that returns the canonical ID, used at every capture() call.

Which ID to pass

PostHog accepts anything stable: a UID, an email or a database ID. For a SaaS, use the database user ID. It exists from account creation and never changes. An email changes when someone moves company or fixes a typo, and the distinct ID cannot follow it: PostHog does not allow identifying a user who was already identified with a different distinct ID.

Put the email, the name and the plan in the second argument. Those are person properties, the attributes you filter, segment and build cohorts on. PostHog recommends passing every person property you have each time you call identify, so the profile stays current. Two details from the docs:

  • $set overwrites a value, $set_once writes it only if the key does not exist yet. Use $set_once for facts that never change, such as the first URL a person visited or their signup date.
  • $set and $set_once are not stored on the event. You cannot break down an event by them; query the person property instead.

When the anonymous person is merged, its properties are added to the identified person. If both have the same property, the identified person's value wins.

If several users share an account, call group() as well, with your account ID as the key. Retention and activation then read per company, as shown in the guide to measuring retention in PostHog.

What identify changes on your bill

The JavaScript SDK defaults to person_profiles: 'identified_only'. In the docs' words, events are anonymous by default and become identified once identify(), alias(), group() or setPersonProperties() creates a person profile. From then on, every event from that user is identified.

That matters for two reasons:

  • Features. Anonymous events work in trends, funnels and SQL insights filtered by event properties. They cannot be used for cohorts, lifecycle insights, person property filters, group analytics or person-based targeting of flags and surveys. Anything about who your users are needs identify.
  • Cost. PostHog says anonymous events can be up to 4x cheaper than identified ones. Events captured before the identify call keep their anonymous price. The PostHog pricing guide works through the identified events line with real volumes.

The practical split for a SaaS: leave the marketing site anonymous, identify inside the product.

The mistakes that split or merge users

The identity resolution guide traces every identity problem to one cause: two IDs that should be one person and are not linked. The symptoms depend on the feature.

Where you see itSymptomWhat happened
FunnelsConversion attributed to the wrong userEvents split across unlinked persons
ExperimentsUser in both control and testTwo unlinked persons, each assigned independently
ExperimentsExposure recorded, conversion missingExposure on the anonymous ID, conversion on the identified ID
Feature flagsDifferent value before and after loginThe ID used for the hash changed
Session replayRecording breaks at logindistinct_id changed mid-session without a link

The five causes worth checking first:

  1. Identify called too late. The signup event fires, then identify runs on the next page. The conversion lands on the anonymous person. Move identify before it.
  2. A generic ID. A bug sends null, undefined or "id" for every user. PostHog blocks a list of these values (including anonymous, guest, email, true, 0 and empty strings): the event is ingested, the merge is refused and an ingestion warning is logged. If your real IDs could collide with one of them, use UUIDs.
  3. Two identified IDs for the same human. The web app identifies with the database ID, the mobile app with the email. PostHog refuses to merge two already identified users and logs a "Refused to merge an already identified user" warning, according to the persons docs. Use the same ID everywhere, or link a second ID with alias() while it is still unused.
  4. No reset at logout. Shared devices collapse several people into one profile.
  5. A catch-all ID on the server. Background jobs sent as "system" or "cron" pile millions of events onto one person. That profile hits a per-ID rate limit, its person data becomes unreliable, and every event counts as an identified event, the expensive kind. The fix in the docs: a random UUID per job run, with $process_person_profile set to false.

When the marketing site and the product live on different domains, the anonymous ID does not follow the visitor on its own. The identity resolution guide says to pass the distinct_id and the $session_id as URL parameters on the link to the app, then initialize PostHog with them. On a shared domain or a cookie readable across subdomains, they persist by themselves.

How to check that it works

Pick a test account, sign up from a private window after clicking a link with UTM parameters, then follow the checklist from the identity resolution guide:

  1. One person. Search for the email. Two person records mean the merge did not happen.
  2. All distinct IDs on that person. The Distinct IDs tab should list the anonymous ID and your user ID.
  3. Events from browser and server on the same timeline, the landing page view included.
  4. The $identify event, carrying both IDs.

Then open your ingestion warnings. "Refused to merge" warnings mean duplicates are piling up and will not merge on their own. Duplicate profiles inflate cohort sizes and flag targeting counts.

What to remember

Identify is three lines of code and the precondition for every funnel that starts before signup. Pass your database user ID, never an email or a generic value. Call identify on app load and right after signup or login, before the conversion event. Call reset at logout. Send the same ID string from the server. Then sign up once yourself and check that one person holds the whole path, from the first page view to the activation event. Once that holds, the drop between visit and signup becomes a number you can price and fix like any other step.

Frequently asked questions

What does posthog.identify() do?

It links the anonymous ID PostHog gave a visitor to the ID you pass, usually your database user ID. The SDK sends an $identify event carrying both IDs, PostHog merges the anonymous person into the identified one, and the events captured before signup now appear on the same person as the events captured after it.

Should I use the email as the distinct ID in PostHog?

PostHog accepts an email, a UID or a database ID. A database user ID is the safer choice for a SaaS, because people change email addresses and the distinct ID should never change. Send the email as a person property in the same identify call so you can still search and filter on it.

Do I need to call identify on every page?

No. PostHog recommends calling it when the app loads and right after login or signup, once per session. If you call it again with the same data without reloading the page, PostHog ignores the repeated calls, so a guard in your auth hook is enough to avoid noise.

Does identify make PostHog more expensive?

It can. With the default person_profiles setting, events are anonymous until identify runs and identified after. PostHog says anonymous events can be up to 4x cheaper than identified ones. Events captured before the identify call stay billed as anonymous, so identifying at login does not reprice the visitor's earlier history.

Sources

  1. PostHog docs, Identifying users: https://posthog.com/docs/product-analytics/identify
  2. PostHog docs, Identity resolution: https://posthog.com/docs/product-analytics/identity-resolution
  3. PostHog docs, Anonymous vs identified events: https://posthog.com/docs/data/anonymous-vs-identified-events
  4. PostHog docs, Persons: https://posthog.com/docs/data/persons
  5. PostHog docs, Person properties: https://posthog.com/docs/product-analytics/person-properties
Colas VandervaereHead of Growth, building Trimtab

Read next