Mixpanel Community Icon

Managing distinct_id: Prioritizing user_id over device ID for tracking

·
·

Why is the distinct_id showing as the device ID when we already have the user_id for that user? Using the device ID may increase the MTU (Monthly Tracked Users) count, especially when a user changes their device or logs in from another device. How can we ensure preference is given to the user_id, and only update the distinct_id to the device ID if the user_id is not present?

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Hi Manoj K., 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

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Based on the knowledge sources provided, I can explain why the distinct_id might be showing as the device ID even when you have a user_id for that user, and how to address this issue.The reason for this behavior is explained in the Identifying Users (Original) FAQ: "The canonical distinct_id is selected by Mixpanel using any of the IDs inside of a cluster. This means that even after identifying your user, Mixpanel may choose your user ID or one of the other IDs inside of the cluster (such as the device ID) to serve as the displayed ID for the user. This is random and not user-configurable."This behavior is part of Mixpanel's identity management system and can indeed lead to the issues you mentioned, such as potentially inflating the Monthly Tracked Users (MTU) count when users change devices or log in from multiple devices.To address this issue and ensure preference is given to the user_id, Mixpanel recommends the following best practice: "As a best practice, please set your chosen user ID as a separate user profile property and event property so that you can always query and see your own chosen user ID."By following this recommendation, you can consistently use your preferred user_id in queries and exports, even if Mixpanel sometimes displays the device ID as the distinct_id.It's important to note that while you can't directly control which ID Mixpanel chooses as the canonical distinct_id, you can ensure that all IDs in the cluster (including both the user_id and device ID) will resolve to the same user in Mixpanel's system.For projects using the Simplified ID Merge API, you can implement this approach by including both $device_id and $user_id in your events. When both are present, Mixpanel will use the $user_id as the distinct_id. Here's an example from the Simplified ID Merge documentation: ```def track_to_mp(request, event_name, properties):

    properties["user_id if the user is authenticated (logged in). if request.user.is_authenticated(): properties["device_id and $user_id as properties. mp.track("", event_name, properties)```By consistently including both $device_id and $user_id (when available) in your events, you can ensure that Mixpanel has the information it needs to properly identify and merge user data, while still being able to query based on your preferred user_id.

    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.