kapa.ai I have a use case where i have some mix panel events that i emit before user has signed up or logged in, i want to make sure that when user signs up i merge the old and new events with one id,i use mixpanel.identify when user signs up or logs in, because before that i dont have an id
Please stand by Sikandar S. as I search the knowledge base. I normally take about 15 seconds or so. 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
You’re already doing the right thing by tracking events before signup/login, then calling mixpanel.identify(<user_id> ) once you know who the user is.Here’s how Mixpanel will handle the merge and what you should ensure: 1. Before signup / login (anonymous state)
- Just call mixpanel.track(...) without identify().
- The JS SDK automatically generates a random $device_id and uses it as distinct_id for all these anonymous events. [JS identity; Simplified overview]2. On signup or login
- Call mixpanel.identify('<USER_ID> ') with your stable app/user ID.
- Then send at least one event after that identify call. This event will contain both $device_id (existing anonymous ID) and $user_id (your user ID), and Mixpanel will merge the anonymous and identified histories into one identity cluster. [Simplified client-side; Example flows]
js
// Anonymous browsing
mixpanel.track('Viewed Landing Page');LBKS // User signs up / logs in
mixpanel.identify(user.id); // sets $user_id
mixpanel.track('Sign Up'); // triggers merge of prior anonymous events
```LBKSLBKS After this, both pre-login and post-login events will be attributed to the same user. [[Simplified example flows](https://docs.mixpanel.com/docs/tracking-methods/id-management/identifying-users-simplified#example-user-flows)]LBKS3. **On logout**
- Call `mixpanel.reset()` to clear the stored `$user_id` and `$device_id` and generate a new anonymous ID for the next visitor/session, so multiple people on the same device don’t get merged together. [[JS identity](https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#managing-user-identity); [Simplified best practices](https://docs.mixpanel.com/docs/tracking-methods/id-management/identifying-users-simplified#best-practices)]LBKS
js mixpanel.track('Log Out'); mixpanel.reset();
- call `identify(user_id)` on signup/login,
- send at least one event after `identify`,LBKSMixpanel will automatically merge the old (anonymous) and new (identified) events under one user.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
How will they merge the events? because before i signup the events i track i want them to merge them to the same user when he signs up kapa.ai
Let me check the knowledge base for you again. One moment! 📚
Mixpanel will do exactly what you want—as long as you use identify() at signup/login and send at least one event afterward.How the merge works depends on which ID Merge API your project uses: ---
1. If you are on Simplified ID Merge (most new projects)
**Flow:1.
- SDK automatically generates a $device_id.
- Your events only have $device_id; distinct_id is set to $device_id (internally as $device:<device_id> ). [Simplified mechanism]2.
- You call mixpanel.identify(user_id). This sets $user_id on future events. [Simplified mechanism]
- Send at least . That event will include both $device_id and $user_id.
- When Mixpanel sees $device_id + $user_id together , it:
- Creates an joining that $device_id and $user_id.
- Retroactively rewrites earlier anonymous events from that $device_id so their distinct_id becomes the $user_id. [Simplified example flows – New User Signup] So all events from “before signup” (with that $device_id) and “after signup” (with that $user_id) become one user in reports.Concrete example from docs:**Before signup: | Event | $device_id | $user_id | distinct_id (by Mixpanel) |
| --- | --- | --- | --- |
| 1 | D1 | | $device:D1 |
| 2 | D1 | | $device:D1 |User signs up, you call identify(U1) and send one event: | Event | $device_id | $user_id | distinct_id (by Mixpanel) | Notes |
| --- | --- | --- | --- | --- |
| 1 | D1 | | $device:D1 ⇒ U1 | retroactively updated |
| 2 | D1 | | $device:D1 ⇒ U1 | retroactively updated |
| 3 | D1 | U1 | U1 | merges D1 ⇒ U1 |All three events now belong to the same user U1. [Simplified example flows]---
2. If you are on Original ID Merge
**Flow:**1. Before signup/login (anonymous)
- SDK uses $device_id as the distinct_id and tracks anonymous events. [Original client-side]2. On signup/login
- You call mixpanel.identify(user_id).
- This sends a special $identify event with $identified_id = user_id and $anon_id = <device_id> . [Original mechanism – $identify]
- Mixpanel merges those two IDs into one identity cluster; after that, any events sent with either the old $device_id or your user_id are treated as the same user. [Original example flows – New User Signup]The result is the same: all pre-signup and post-signup events from that browser/app session become one user.---
What you need to do
On the client: js // Anonymous usage mixpanel.track('Viewed Page'); // ...other anonymous events...LBKS// When user signs up / logs in mixpanel.identify(user.id); // crucial mixpanel.track('Sign Up'); // for Simplified, this event triggers the mergeLBKSAs long as you: - let the SDK handle anonymous tracking before signup, and
- call identify(user_id) on signup/login (and send at least one event afterward if using Simplified),Mixpanel will merge all earlier anonymous events from that device with the new signed-in user, so you can analyze their full journey in a single profile. [Simplified client-side identity; Original client-side identity]
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
