how to server side identify. I am using simplified merge project
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
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 $device_id for anonymous events: When tracking events for anonymous users, set the $device_id property to the Anonymous ID you generated.
3. 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 $device_id and $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 uuid
def track_to_mp(request, event_name, properties):
properties["$device_id"] = request.cookies.get('SESSION_ID')
if request.user.is_authenticated(): properties["$user_id"] = request.user.username
mp.track("", event_name, properties)
LBKSIt'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](https://docs.mixpanel.com/docs/tracking-methods/id-management/identifying-users-simplified#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.
