we allow user to use our App in non logged in State , and there is an option, user can also login with any email here we face challenge, distinct ids get changed, and while creating Funnel on MixPanel , it treats them as different user but ideally they are same what can be done in this case
Hi Rohit M., 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
This is a common challenge with identity management in Mixpanel. When users transition from anonymous (non-logged in) to authenticated (logged in) states, you need to properly link these identities to ensure they're treated as the same user in your analytics.
Solution: Implement Proper Identity Management
You should implement Mixpanel's identity management to connect the anonymous user with their logged-in identity. Here's how:
1. Call .identify()
when users log in
When a user logs in with their email, call the .identify()
method with their user ID (which could be their email or a database ID): LBKS// When user logs in mixpanel.track('sign in');LBKS// Identify the user with their ID mixpanel.identify('user@​[example.com](http://example.com)');LBKS
This will link their pre-login (anonymous) activity with their post-login activity, ensuring they're treated as a single user in funnels and other reports Identifying Users (Simplified).
2. Call .reset()
when users log out
When users log out, call the .reset()
method to generate a new anonymous ID: LBKS// When user logs out mixpanel.track('log out');LBKS// Clear local storage and generate new distinct_id mixpanel.reset();LBKS
This ensures that if multiple users share the same device, they won't be incorrectly considered as a single user Mixpanel SDKs: JavaScript.
Best Practices
1. Use a consistent user ID: Use an ID that is unique to each user and doesn't change. While email is convenient, if users can change their email, consider using a database ID instead Identifying Users (Simplified).2. Track user ID as a property: Track the user's unique identifier as both a super property and user property to assist in troubleshooting Identifying Users (Simplified).3. Be aware of mapping time: It may take up to 24 hours for the ID mapping to fully propagate through Mixpanel's system. For debugging, the Activity Feed view updates in near real-time Identifying Users (Original).By implementing these practices, your funnels should correctly track users as they move from anonymous to logged-in states, treating them as the same user throughout their journey.
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.
kapa.ai here are two cases-
user logs in with fresh email in non-logged in state, then we have same id for them, and even if user logs out, the id should not change, else funnel data wont be correct as ideally they are same user, and is not dependent if they are logged in or not.
user logs in with already existing email, having an id already, which is different from device unique id, how to handle this case
Let me check the knowledge base for you again. One moment! 📚
I'll address both of your identity management scenarios in Mixpanel:
Case 1: User logs in with fresh email in non-logged in state
When a user logs in with a fresh email, you should call .identify()
with their user ID (email or database ID). However, you're right that if they log out, you don't want to change their ID since they're still the same user.The standard recommendation is to call .reset()
on logout, but this would generate a new distinct ID, which isn't what you want in this case. Instead, you could: 1. Skip calling .reset() at logout - This would maintain the same distinct ID for the user whether they're logged in or not Identity Management Overview.2. Store the user ID - Store the user ID in local storage when they first log in, and continue using it even after logout.This approach aligns with the best practice mentioned in the original identity management documentation:
"Not calling .reset()
at this point also prevents hitting the 500 ID cluster limit should the same user log back in there will be be new $device_id
to link into the cluster." Identifying Users (Original)
Case 2: User logs in with existing email on a new device
When a user logs in with an existing email on a new device (with a different device ID), you should: 1. Call .identify()
with their consistent user ID (email or database ID) when they log in: LBKSmixpanel.identify('user@​[example.com](http://example.com)');LBKS
This will link their current device ID with their existing user ID in Mixpanel, creating an identity cluster that contains both IDs. All events from both devices will be attributed to the same user Identifying Users (Simplified).From the documentation:
"The user logs in. Call .identify(U1)
to tell us that the user on this device is the same $user_id
we have seen before... Moving forward, any events tracked using either U1, D1, or D2 will resolve to the same user." Identifying Users (Original)This ensures that all activity from this user, regardless of which device they use, will be correctly attributed to a single user in your funnels and other reports.
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.