Identity and merge

How an anonymous visitor becomes a person: the three ids, what identify merges and rewrites, why alias differs, and what splits one person in two.

Identity is the part of an analytics integration that is most expensive to get wrong, because the damage is retroactive: a wrong id does not raise an error, it quietly turns one person into two and every funnel built on them is understated. This page is the contract, written against what the service actually does.

The three ids

Stored on every event is a single distinct_id, derived on the way in:

  1. did, if a trusted writer (a Server key) sent one.
  2. otherwise uid.
  3. otherwise aid.

An event with none of the three is dropped, silently. There is nobody to attribute it to, and the alternative would be inventing a person.

A Project token is an untrusted writer, so a did it sends is removed before the derivation runs. That is deliberate: a credential that ships in a page cannot be allowed to claim to be an arbitrary person. From a browser, send aid always and uid once you know it.

What identify does

identify binds an anonymous history to a person. Send it once, at sign-in or sign-up:

curl -X POST https://t.intelligent.page/v1/identify \
  -H 'content-type: application/json' \
  -H 'x-analytics-token: ipa_pub_REPLACE_ME' \
  -d '{ "distinctId": "anon_9f2c41", "userId": "user_1024",
        "traits": { "email": "ada@example.com", "plan": "free" } }'

Or as an event in any batch, which is what the SDKs and the Mixpanel shim do:

{ "id": "…", "ts": "2026-09-28T09:15:00.000Z", "event": "$identify",
  "aid": "anon_9f2c41", "uid": "user_1024", "did": "user_1024" }

When the merge is committed, four things happen:

  1. The mapping is recorded. The anonymous id now resolves to the user id, permanently, for this Project.
  2. Recent history is rewritten. Events and sessions carrying that anonymous id and no user id, from the last 30 days, are re-attributed to the person.
  3. The profiles are folded together. The anonymous profile's first-seen, last-seen, event count, session count and first-touch attribution (first campaign, first UTM) are merged into the person's, then the anonymous profile is retired.
  4. Traits are applied. If you sent traits, a $set follows and updates the person's profile.

That is why the answer is two events:

{ "accepted": 2, "events": ["$identify", "$set"] }

The 30-day window

The rewrite reaches back 30 days and no further. Older anonymous events keep their anonymous id: they still exist and still count, but they are not that person's history.

The practical consequence: identify as early as you legitimately can. A visitor who browsed for two months before signing up will have their first month attributed to an anonymous id forever. Nothing can be done about it after the fact, and a second identify will not extend the window.

Idempotence

Repeating an identify for the same pair is harmless but not free: it re-runs the rewrite. Clients should send it once per (anonymous id, user id) pair and remember that they have. Our own web client keeps a marker in localStorage keyed on exactly that pair, so a page reload does not re-emit.

What alias does, and does not

alias adds a second id for a person who is already known:

curl -X POST https://t.intelligent.page/v1/alias \
  -H 'content-type: application/json' \
  -H 'x-analytics-token: ipa_pub_REPLACE_ME' \
  -d '{ "distinctId": "user_1024", "alias": "ada@example.com" }'

It records the mapping and nothing else. No history is rewritten, no profile is retired, no counters are merged. From now on, events arriving under the alias resolve to the same person; events that arrived under it before stay where they were. Replaying an alias twice is a true no-op.

Use identify for anonymous to known. Use alias for known to known: a second login identifier, an email address alongside an internal id, a legacy id after a migration.

alias refuses when the alias equals the distinct id (400, field alias).

Reset and sign-out

On sign-out, drop the user id and mint a new anonymous id. Keeping the old one attributes the next visitor on a shared machine to the person who just left.

Our own web client does exactly this: it clears the stored user id, regenerates the anonymous id and starts a new session. There is nothing to send to the service; reset is purely client-side state.

Groups

A group attaches events to an organisation rather than an individual. A group is a pair: group_key, which kind of group it is, and group_id, which one.

curl -X POST https://t.intelligent.page/v1/group \
  -H 'content-type: application/json' \
  -H 'x-analytics-token: ipa_pub_REPLACE_ME' \
  -d '{ "distinctId": "user_1024", "groupKey": "company", "groupId": "acme",
        "traits": { "plan": "enterprise", "seats": 40 } }'

Or as an event, with the pair in properties:

{ "id": "…", "ts": "…", "event": "$group", "did": "user_1024",
  "props": { "$group_key": "company", "$group_id": "acme", "plan": "enterprise" } }

On commit, the group row is upserted: traits merge, first-seen and last-seen move, and this person's events in the same batch are stamped with the pair so a report can group by company without a join. Properties other than the pair itself are the group's traits.

Declare the group keys your Project uses in its settings (at most 10). Common ones: company, shop, workspace, account.

Profiles

A person's profile is the current state of who they are, as against events, which are what they did.

  • $set merges properties into the profile. This is what traits on identify produce, and what Mixpanel's people.set maps to.
  • $profile is the trusted-only richer form: its profile object writes the known columns (email, name, plan, subscription status, signed-up and onboarded timestamps) rather than free properties. It needs a Server key.

Profiles are overwritten, never versioned. If you need to see a change over time, send an event as well.

Mistakes that split a person in two

The last one is worth a rule: choose one id namespace per Project and use it everywhere. Whichever id your backend calls a user by should be the uid in the browser, the did on the server, the distinct_id on mobile and the customer id in a connector.

Next