Mixpanel Community Icon

Setting Up Multiple Distinct IDs in Server and Frontend Packages

·
·

How to set multiple distinct id both in server level as well using frontend package?

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

    Hi Javed A., 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
    ·
    ·

    I'll explain how to work with multiple distinct IDs in Mixpanel, both at the server level and using frontend packages.

    Multiple Distinct IDs in Mixpanel

    First, it's important to understand that your approach depends on which ID management system your Mixpanel project is using:

    Original ID Merge

    If you're using Original ID Merge, you can associate multiple IDs with a single user: 1. Frontend Implementation: You can use the identify() method to link an anonymous ID with a user ID:

    mixpanel.identify('USER_ID'); ```LBKSLBKS This sends an `$identify` event that links the current device ID with your user ID [Identifying Users (Original)](https://docs.mixpanel.com/docs/tracking-methods/id-management/identifying-users-original#example-user-flows).LBKS2. **Server-side Implementation**: For server-side tracking, you need to: - Generate and manage the anonymous IDs yourself - Send an `$identify` event to merge IDs: LBKS ```LBKS { "event": "$identify", "properties": { "$identified_id": "<TRUE_USER_ID> ", "$anon_id": "<ANONYMOUS_ID> ", "token": "<YOUR_PROJECT_TOKEN> " } } ```LBKSLBKS You can also use the `$merge` event to merge any two identifiers: LBKS ```LBKS { "event": "$merge", "properties": { "$distinct_ids": [ "user_id_1", "user_id_2" ] } } ```LBKS [Identifying Users (Original)](https://docs.mixpanel.com/docs/tracking-methods/id-management/identifying-users-original#server-side-identity-management)

    Simplified ID Merge

    If you're using Simplified ID Merge, the approach is different: 1. Frontend Implementation: The SDK handles most of the work. You just need to call identify() when the user logs in.2. Server-side Implementation: You should set both $device_id and $user_id properties in your events:

    Example in Python

    def track_to_mp(request, event_name, properties):

    Set $device_id to anonymous ID

    properties["$device_id"] = request.cookies.get('SESSION_ID')

    Set $user_id if user is logged in

    if request.user.is_authenticated(): properties["$user_id"] = request.user.username

    mp.track("", event_name, properties)

    Important Considerations

    1. Original ID Merge Limitation: Each user's ID cluster is limited to 500 distinct IDs. If you reach this limit, new IDs can't be merged, creating duplicate users Migrating to Simplified ID Merge.2. Simplified ID Merge Limitation: This system supports only one User ID ($user_id) per ID cluster. If you need multiple User IDs per user (like both email and phone number), you should use Original ID Merge Considerations when Migrating.Choose the approach that best fits your requirements for managing user identity across your application.

    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.