Sub topic 2
Who is a user? Identity and counting
Every funnel, cohort, and retention report counts users. The numbers only mean something if you know how the tool decides that two events came from the same person. This chapter covers how Amplitude and Mixpanel assign identity, how that changes your counts, and which mistakes inflate or shrink them.
This chapter assumes you know what an event and a property are, and you can read a simple funnel report. The SQL example is optional.
Three kinds of identifier
An analytics tool does not see people. It sees identifiers attached to events. Three kinds matter:
- Device ID: a random value the SDK generates and stores in the browser or app. It exists before login. It changes when the visitor clears cookies, switches browsers, or reinstalls the app.
- User ID: a value your own system supplies after login, such as a database key. It follows the person across devices. You must set it yourself.
- Tool-internal ID: the identifier the tool uses for counting. Amplitude calls it the Amplitude ID. Mixpanel calls it the distinct ID, which is derived from the device and user IDs.
A report counts distinct internal IDs. The identifiers you send determine how those IDs are formed.
| Concept | Amplitude | Mixpanel |
|---|---|---|
| Before login | Device ID | `$device_id`, with a distinct ID prefixed `$device:` |
| After login | User ID | `$user_id` |
| Linking call | `setUserId` | `identify` |
| Forget the current user | `reset` | `reset` |
| What reports count | Amplitude ID | Distinct ID, after merging |
Anonymous to identified
A typical visitor reads a pricing page, starts signing up, creates an account, and later returns on a phone. The first events carry only a device ID. After signup, your code sets the user ID. The tool then links the earlier anonymous events to that user, so the funnel counts one person.
The linking only happens if the device ID and user ID appear together, either on one event or through an explicit identify call. A user ID set on the phone links that phone to the same person, which is why user IDs are the only reliable way to count across devices.
Sending identity correctly
The code below shows the full lifecycle. Events before login are anonymous. The identify call links them. Logout resets the identity.
import * as amplitude from '@amplitude/analytics-browser';
import mixpanel from 'mixpanel-browser';
amplitude.init('YOUR_AMPLITUDE_API_KEY');
mixpanel.init('YOUR_PROJECT_TOKEN');
// 1. Anonymous: both SDKs attach a generated device ID.
amplitude.track('Sign Up Started', { plan: 'pro', source: 'pricing_page' });
mixpanel.track('Sign Up Started', { plan: 'pro', source: 'pricing_page' });
// 2. Account created: tell each tool who this is.
amplitude.setUserId('user_123');
mixpanel.identify('user_123');
amplitude.track('Sign Up Completed', { plan: 'pro', source: 'pricing_page' });
mixpanel.track('Sign Up Completed', { plan: 'pro', source: 'pricing_page' });
// 3. Logout: start a fresh anonymous identity.
amplitude.reset();
mixpanel.reset();Two details are easy to miss:
- Call identify or
setUserIdas soon as you know the ID, and before you send the next event. Events sent before the link are still merged in both tools, but late identification leaves a stretch where live reports show two people. - Always call
reseton logout. Without it, the next person on a shared device inherits the previous user's identity.
Mixpanel's ID merge versions
Mixpanel projects use one of two identity systems. Check which one your project uses before you debug counts.
- Simplified ID Merge is the current default for new projects. Pre-login events carry
$device_id. Post-login events carry$user_id. Callingidentifylinks all device IDs seen with that user ID, and the merge is permanent. - Original ID Merge is the older system. It relies on
aliasto connect an anonymous ID to a user ID, and calling it in the wrong order or twice creates separate users that you cannot fully repair.
In both systems, a merge applies going forward and to stored data. You cannot undo it by changing your code later. A wrong identify call is therefore costly. For example, if a shared kiosk identifies two customers under one device, the tool may merge them into one person permanently.
Amplitude's identity behavior
Amplitude maps each device ID and user ID pair to an Amplitude ID. Events with the same user ID share one Amplitude ID. Events from a device that was later given a user ID are folded into that user's profile. One user ID on many devices still counts as one user.
If a device first sees user_A and then user_B without a reset, Amplitude can attribute the later events to the first user's device history. This is the same shared-device problem described above.
Amplitude also has a project-level setting for how users without a user ID are treated. Some projects count only identified users in reports by default, which changes totals compared with a project that counts everyone. Check this setting when two charts disagree.
Unique users, event totals, and active users
A funnel reports unique users per step by default. That is not the same as counting events.
| Measure | What it counts | Example for one person who triggers `Sign Up Started` 3 times |
|---|---|---|
| Event totals | Every event occurrence | 3 |
| Uniques | Distinct users who did the event at least once | 1 |
| Active users | Distinct users who did any qualifying event | 1 |
A funnel step's conversion rate is the unique users who reached step N divided by the unique users who reached step N−1. If you switch a chart from uniques to totals, the percentages can exceed 100% or fall out of step with each other. When a stakeholder quotes a number, ask which measure they used.
Time bucketing matters too. A user who is active on Monday and Tuesday is one unique user in a weekly chart but two in a daily chart. Summing daily uniques across a week overcounts.
What a funnel does behind the scenes
This query shows identity resolution in plain SQL. It assumes an events table with device_id, a nullable user_id, event_name, and event_time. It builds a device-to-user map, resolves a person ID for every event, and compares the raw device count with the resolved person count.
WITH device_map AS (
SELECT device_id, MIN(user_id) AS user_id
FROM events
WHERE user_id IS NOT NULL
GROUP BY device_id
),
resolved AS (
SELECT
e.event_name,
e.event_time,
e.device_id,
COALESCE('u:' || e.user_id, 'u:' || m.user_id, 'd:' || e.device_id) AS person_id
FROM events e
LEFT JOIN device_map m ON m.device_id = e.device_id
)
SELECT
COUNT(DISTINCT device_id) AS device_count,
COUNT(DISTINCT person_id) AS person_count
FROM resolved
WHERE event_name = 'Sign Up Started';The u: and d: prefixes keep user IDs and device IDs from colliding. If the same person starts signup on a laptop and a phone, the device count is 2 and the person count is 1, provided both devices later get the same user ID. The gap between the two numbers is a quick measure of how much identity resolution changes your reports.
The MIN(user_id) line is a simplification. If two users share a device, it silently picks one. Real tools have the same weakness in different forms.
Common identity errors and their effect
- No identify on login: pre- and post-login activity counts as two users. Funnels that cross the login step show an artificial drop at the step where the identity changes.
- No reset on logout: shared-device users merge, so counts fall and one person gets another's history.
- Changing the user ID format: switching from an email to a database key makes every existing user appear as a new user. Pick a stable, non-personal key and keep it.
- Identifying on the wrong value: using an email or a session ID as the user ID breaks when the email changes or the session ends.
- Cross-domain and cross-app journeys: a visitor who moves from a marketing site to the app gets two device IDs unless you pass the ID across or identify on both sides. The funnel then loses people between steps.
- Server-side events without the device ID: backend events often have only a user ID. If a pre-login backend event has neither, it cannot be linked to the browser journey.
- Test and bot traffic: internal accounts and crawlers inflate uniques. Filter them with a property or exclude them in project settings.
Checking your own project
- Pick one test account and log in on two browsers.
- Open the user's event stream in each tool and confirm both devices appear under one user.
- Log out, log in as a second test account on the same browser, and confirm the second account has only its own events.
- Run a one-step chart of
Sign Up Startedwith uniques and with totals. The totals should be equal to or larger than the uniques.
If step 2 shows two users, your identify call is missing or runs too late. If step 3 shows a combined history, the reset call is missing.
Exercise
A funnel with the steps Pricing Page Viewed, Sign Up Started, and Sign Up Completed shows 1,000 users at step 2 and only 400 at step 3. You then notice that your app calls identify only after the signup form is submitted and that logout does not call reset. Name two ways identity could distort the 40% figure, and say what you would check first.
Show answer
First, pre-login events and post-login events might be counted as different users if identification is late or missing, which lowers step 3 because the person who completed signup is not the same counted user as the one who started it. Second, without a reset on logout, different people on shared devices can be merged, which makes the counts at each step unreliable in either direction. Check first whether one test user who completes signup appears as a single user with events on both sides of the login step, and compare step 1 uniques against your own database count.