Search code examples
mixpanel

Mixpanel anonymous and known user events


I am attempting to implement Mixpanel and struggling with the connection between anonymous events and then eventual known user events.

Say I have an anonymous user that adds a product to cart. I’m currently sending an add to cart event with an anonymous identifier.

Then later they make the purchase. At this point I know the user. I create a user at this point using a hashed email address for the user/distinct ID and send a purchase event. Only the purchase event is showing as attached to the user.

I’ve tried various methods of identifiers or aliases with no luck. Given the above scenario what is the order of events that needs to happen and how do I successfully link the past events to the user profile?

I am in C# so no official SDK exists.


Solution

  • I finally heard back from Mixpanel support on this and their solution worked for me so I wanted to post it here for others. The documentation detailing this is currently incorrect so by following their instructions on how to do this you will not succeed.

    For anonymous events you need to pass the $device_id and distinct_id which is the anonymous identifier of your user. The values for both need to be set and need to be the same.

    Once known, continue to set the $device_id and distinct_id to the anonymous identifier, but also set $user_id to the known user identifier. The first time Mixpanel receives an event with all of this information it will attempt to merge the values into one. You can then continue to send both values.

    When you create the user set the distinct_id to the known user identifier.