How is it that the User ID isn't set in some events, even though I can see it in the 'View Users – Activity Feed'? It's incorrectly grouping some users under the cohort that only uses Device ID, even though those users actually have a User ID and when I breakdown by User ID it says not set and have triggered the event that should exclude them from that group.
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
This situation can occur due to the way Mixpanel handles identity merging and the timing of when the $user_id property is set on events.
Key Points:
1. Anonymous Events and Identity Merge Timing:
When a user first interacts with your product anonymously, events are tracked with only a $device_id. After the user logs in or signs up and you call .identify(<user_id> ), subsequent events will include both $device_id and $user_id. However, events that occurred before identification will not have $user_id set in their properties—they only have $device_id. Mixpanel retroactively merges these events in the Activity Feed, so you see the full user journey under the correct user, but the original events themselves still lack the $user_id property in their raw data. This is why, when breaking down by $user_id, those earlier events show "not set" even though the Activity Feed correctly attributes them to the user Identifying Users (Simplified) – Example User Flows.
2. Cohort and Breakdown Behavior:
Cohorts or breakdowns that rely on the presence of $user_id will only include events where $user_id was actually set at the time of tracking. If a user triggered an event before being identified, those events will be grouped under "Device ID only" or "User ID not set," even if the user later logs in and is merged in the Activity Feed. This can lead to users being included in cohorts based on device ID, even though they have a user ID, simply because the relevant events were tracked before identification.
3. Best Practice:
To ensure accurate cohorting and breakdowns, always call .identify(<user_id> ) as soon as the user is known (e.g., at login or signup), and send at least one event after identification. This ensures that all subsequent events have $user_id set. However, you cannot retroactively add $user_id to events that were tracked before identification Client-side Identity Management.
Summary: The discrepancy arises because Mixpanel’s Activity Feed merges user activity across device and user IDs for a unified view, but the actual event properties remain as they were at the time of tracking. Cohorts and breakdowns operate on the raw event properties, not the merged view, which is why you see "User ID not set" for some events even though the user is correctly merged in the Activity Feed.
If you need to exclude users from a cohort based on a post-login event, ensure that event is always triggered after .identify(<user_id> ) so $user_id is present on the event.
For more details, see:
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.
