Mixpanel Community Icon

how to server side identify. I am using simplified merge project

·
·

how to server side identify. I am using simplified merge project

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

    Hi Zeyad Y., 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
    ·
    ·

    To implement server-side identification in a Mixpanel project using Simplified ID Merge, you need to follow these steps: 1. Generate an Anonymous ID: Create a unique identifier for each user session, typically a UUID. Store this in a cookie or session.2. Set user_id when the user is authenticated: Once the user logs in or is identified, set the $user_id property to their authenticated ID (e.g., username or database ID).4. Include both user_id in events: After authentication, include both the $device_id (Anonymous ID) and $user_id (Authenticated ID) in your events. This triggers the merging of the two IDs.Here's a pseudocode example to illustrate this process: ```import uuiddef track_to_mp(request, event_name, properties):

    properties["user_id if the user is authenticated if request.user.is_authenticated(): properties["$user_id"] = request.user.username # Track the event (note: leave the first argument blank) mp.track("", event_name, properties)```It's important to note that you don't need to manually set the distinct_id property, as Mixpanel will determine it based on the presence of $user_id and $device_id.For more detailed information, you can refer to the Server-side Identity Management section in the Mixpanel documentation.

    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.