How can I match my user id to the mixpanel user or device id for reporting?
Hi Stephen S., 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 match your user ID to the Mixpanel user or device ID for reporting, you need to properly implement user identification in Mixpanel. Here's how you can do it: 1. For anonymous users, Mixpanel automatically generates a $device_id
. This serves as the anonymous ID for the user.2. When a user logs in or signs up, you should call the .identify()
method with your chosen user ID. This links the anonymous $device_id
to your user ID.3. For server-side tracking, you need to manage the IDs yourself. Set the $device_id
for anonymous events and both $device_id
and $user_id
for identified users.Here's an example of how to implement this in PHP: LBKS<?php // import dependencies require 'vendor/autoload.php';LBKS// create an instance of the Mixpanel class $mp = Mixpanel::getInstance("YOUR_PROJECT_TOKEN");LBKS// calling identify will attach the "USER_ID" // as the $user_id event property to all events moving forward $mp-> identify("USER_ID");LBKS// when a $user_id/$device_id pair is detected in the same event for the first time, // a merge is triggered to map the 2 IDs together. $mp-> track("sign-up", array( '$device_id' => "ANON_ID", '$user_id' => "USER_ID" ));LBKS?> LBKS
This approach ensures that your user ID is properly linked to Mixpanel's internal IDs for accurate reporting.As a best practice, you should also set your chosen user ID as a separate user profile property and event property. This allows you to always query and see your own chosen user ID in reports.For more detailed information, you can refer to these resources:
- Identifying Users (Simplified)
- Mixpanel SDKs: PHP
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.