Script to update Mixpanel user identity for historical data • Find all device IDs associated with each event-level attribute userid • Identify the oldest device ID for each user • Link all device IDs to the canonical user ID (which is the event-level attribute userid) • Set the user profile using the oldest device's profile data for attributes like initial UTM source, etc. please confirm if this script flow works or if anyone has other suggestions
Hi Shrikant M., 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
Your proposed script flow aligns well with Mixpanel’s recommended approach for migrating to the Simplified ID Merge system, but there are some important clarifications and best practices to consider:
1. Find all device IDs associated with each event-level attribute userid
- This is a valid first step. You need to map all $device_id
s (anonymous IDs) that have been associated with each userid
(your canonical user ID) in your historical data.
2. Identify the oldest device ID for each user
- This is reasonable if you want to use the oldest device’s profile data as the source of truth for initial user attributes (like UTM source). There is no explicit Mixpanel requirement to use the oldest device, but it’s a common approach for setting initial attribution.
3. Link all device IDs to the canonical user ID (the event-level attribute userid
)
- In the Simplified ID Merge system, you do this by sending an event for each $device_id
/$user_id
pair, where both are present in the event properties. This triggers Mixpanel to merge the anonymous and identified states for that user. You can use a dummy event (not named $identify
, $create_alias
, or $merge
) for this purpose. For example:
"event": "historical_identity_link",
"properties": {
"token": "YOUR_PROJECT_TOKEN",
"$device_id": "DEVICE_ID",
"$user_id": "USER_ID"
}
}
```LBKS This will merge the device and user IDs as required by the Simplified ID Merge system. You can send these via the Import API or other supported ingestion methods. Make sure to include a unique `$insert_id` for deduplication if you are backfilling data [Understanding Simplified ID Merge](https://docs.mixpanel.com/docs/tracking-methods/id-management/migrating-to-simplified-id-merge-system#understanding-simplified-id-merge) [Backfilling Historical Data](https://docs.mixpanel.com/docs/tracking-methods/id-management/migrating-to-simplified-id-merge-system#backfilling-historical-data).
4. Set the user profile using the oldest device's profile data for attributes like initial UTM source, etc.
- You can set user profile properties using the Engage API or Warehouse Connector. For historical profile properties, Mixpanel recommends using the Warehouse Connector, as it is the only supported method for importing historical profile data in bulk. Make sure to set the profile for the canonical user ID ($distinct_id
= userid
) after the identity merge, as properties set on device IDs before merging are not preserved How do I set the initial set of profile properties for the user? Identifying Users (Simplified) FAQ.---
Additional Suggestions & Considerations
- Order of Operations: Ensure that the identity merge (step 3) is completed before setting user profile properties (step 4), so that the properties are attached to the correct, merged user profile.
- Profile Data Preservation: Any profile properties set on $device_id
before merging will not be preserved after the merge. Always set or re-set them on the canonical $distinct_id
(which will be the userid
in Simplified ID Merge).
- Deduplication: Use $insert_id
for each event to avoid duplicate data during backfill.
- Testing: Start with a small batch to verify that merges and profile updates work as expected before running at scale.---Summary:
Your script flow is correct and matches Mixpanel’s recommendations for identity merging and profile backfilling in the Simplified ID Merge system, provided you follow the above best practices and use the appropriate APIs for event and profile ingestion.If you need to import historical profile properties in bulk, use the Warehouse Connector, as there is no other supported method for bulk profile import How do I set the initial set of profile properties for the user?.If you have further questions or need code samples for a specific step, let me know!
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.