How do I connect an event tracked in an anonymous state on the server side with a client side event tracked when identified using a user ID? Bear in mind for client side we use Mixpanel device id generated for unknown while on the server side we will use a UUID generator? There is a disconnect
Hi event, Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To connect an event tracked in an anonymous state on the server side with a client-side event tracked when identified (using a user ID), you must ensure that the same anonymous identifier (the device ID) is used on both the client and server sides before the user is identified.Key Points:If the server and client use different anonymous IDs, Mixpanel cannot automatically merge the pre-login (anonymous) and post-login (identified) events for the same user, because it will treat them as separate users.
How to Bridge the Gap
1. Share the Client-Side $device_id with the Server:
- When the client (browser/app) generates a $device_id
, expose this value (e.g., via a JavaScript variable or API endpoint).
- When making server-side requests, send this $device_id
along (e.g., as a custom HTTP header or in the request body).
- On the server, use this value as the $device_id
property for anonymous events.2. Track Events:
- For anonymous events, both client and server should use the same $device_id
.
- When the user logs in, call .identify(<user_id> )
on the client, which will merge the $device_id
and $user_id
in Mixpanel.
- On the server, start including $user_id
in events after login, but continue to include the same $device_id
at least once to trigger the merge.3. Result:
- Mixpanel will merge the anonymous and identified event streams, attributing all events to the same user profile.Example (Server-side, Python pseudocode):Important:
If you generate a UUID on the server that is not the same as the client-side $device_id
, there will be a disconnect and Mixpanel will not merge the identities. The only way to connect the two is to ensure the same identifier is used on both sides for the same user/session.Summary:
You must pass the client-generated $device_id
to the server and use it for anonymous events. If you use a different UUID on the server, Mixpanel cannot connect the anonymous and identified events for the same user, resulting in fragmented user profiles and analytics.Learn more about the mechanism and best practices here.
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.
Let me check the knowledge base for you again. One moment! 📚
I'm sorry, but the knowledge sources do not provide explicit information on the exact algorithm or method Mixpanel uses to generate the client-side $device_id
(anonymous ID) in an unknown state. The documentation only states that Mixpanel's client-side SDKs automatically generate a $device_id
that is local to the device, and recommends using this same value on the server side to ensure identity merging works correctly. However, it does not specify how to generate a UUID on the server that will match the one generated by the Mixpanel client SDKs.The recommended approach is to retrieve the $device_id
generated by the client SDK and pass it to your server, rather than trying to generate a matching UUID on the server. This ensures consistency and proper identity merging between client and server events Server-side Identity Management (Simplified).If you need to connect anonymous events across client and server, you should expose the client-side $device_id
(e.g., via JavaScript) and send it to your backend, then use it as the $device_id
for server-side events. There is no documented way to independently generate a matching UUID on the server.
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.