26

I'm adding Mixpanel to my web application and I'm curious about the "process" around what happens when a user transitions from "anonymous" (not logged in/registered) to "identified" (when they register / create an account on the site).

If a user comes in and is new to the site, they get an anonymous UUID (according to the documentation). The documentation also says that Mixpanel can not translate between IDs at this time.

Does this mean Mixpanel is incapable of handling the transition of a non-registered user to a registered user, and keep track of their events from before they became a registered/identified user?

If so, does anyone have experience with working around this? How'd you go about it?

Jim Rubenstein
  • 6,836
  • 4
  • 36
  • 54

3 Answers3

29

As of December 2012, you can now use the mixpanel.alias method call to alias two ids:

https://mixpanel.com/docs/integration-libraries/using-mixpanel-alias

From the above docs:

John comes to your website, example.com, for the first time. He is assigned a randomly generated ID (perhaps 123123) by Mixpanel. Everything he does is associated with that ID.

After clicking through a few pages, he successfully signs up. On the signup confirmation page, you call mixpanel.alias("john@hotmail.com"). This doesn't actually change his ID - he is still being identified using the random ID we originally assigned him.

What it does do is add the ID "john@hotmail.com" to a lookup table on our end. Whenever we see data for "john@hotmail.com", we know to remap it to 123123, his original ID.

So, you can start calling mixpanel.identify("john@hotmail.com") on all your pages, and your events, funnels, and retention will all continue to work perfectly.

loopj
  • 1,599
  • 1
  • 15
  • 12
  • 8
    Thanks for this, Mixpanel's API documentation is EXTREMELY poorly worded. It states, `You can call this function to override a previously set unique ID for the user. Mixpanel cannot translate between IDs at this time, so changing the ID will make them appear to be a new user.`, which makes it sound like `mixpanel.identify()` creates a new user instance each time it is called! – professormeowingtons Jun 03 '13 at 23:56
  • where can i find the user information later on in the mixpanel dashboard ? I was expecting to find it as a property. But it's not there. – Rob Anderson Mar 04 '14 at 14:05
  • @RobAnderson User profiles are maintained under "Explore" paragraph of "People" section – Kirill Slatin Sep 03 '15 at 01:03
11

There are ways to make this work. But what you are really asking for is a feature called distinct id aliasing, which would allow you to reference one distinct_id ID to another. Unfortunately, we don't offer that right now. This turns out to be a much harder issue than you'd expect due to the unique nature of the data-store we wrote for mixpanel.

In the meantime, I can give you a few strategies to get around this limitation:

  • When a user first comes to your website, set a distinct id for them which you generate internally. Once they register for an account, reference that distinct_id in your user detail table, and then continue to register subsequent events with that id. Each subsequent time a user auths, use the stored value as the distinct id. Hopefully when they return the cookie will still be around, and you will capture all the events without a hitch.

  • You could, also, let mixpanel give them an auto-issued distinct_id value, and then grab that at the time of registration by using mixpanel.get_property() then add that to your users table, and use that when you identify them in the future.

  • But what if they auth from one machine and then come on from another, or a different browser, or from a mobile device? Then the time in between when they hit your site and when they auth they'll be issued a new distinct_id by your site... and there is no way to alias! The solution here is a bit hackier. The only way to get that data is to log those events that were sent before the authentication (maybe server-side) and then send them via HTTP specification to the rest API with the correct distinct_id once the user auths. As long as you keep the correct time stamps, it will all appear correctly, chronologically within mixpanel. If the user never auths, then you can have the logged events time out and send them anyways.

Would either of these work for you?

phillee
  • 2,227
  • 2
  • 19
  • 28
  • 1
    I presumed there was not a way to alias distinct id's together; i was just hoping I was wrong. We implemented the internally generated distinct id solution, and it should work for most cases - it's just more management and overhead to keep track of a second distinct identifier. Anyway, thanks for the response. I assume the "we" in your response means you work @ mixpanel, and you have mixpanel.com listed in your profile - so I'll award the answer here - as it's authoritative (: – Jim Rubenstein May 24 '12 at 12:16
  • 2
    And now the feature exists: https://mixpanel.com/docs/integration-libraries/using-mixpanel-alias – raylu Dec 14 '12 at 23:43
  • @WoodySchneider - is there any better solution for #3 yet or still best to log and post after the fact with the correct ID? – dsldsl Apr 02 '13 at 00:10
  • @WoodySchneider Coming back to this question 4 years later - just wondering if there is any update within the core API? Not seeing it in the docs... – Owen Apr 17 '16 at 03:36
  • @Woody Schneider is there any better solution for point 3 you have mentioned in your solultion? if not then how can i get mixpanel inbuilt property (City, Browser etc.) in my client side, so that i can send these data to our server? – Mukund Kumar Mar 17 '17 at 12:47
  • @woody-schneider "In the meanwhile" means forever? its november and still happening :P – Daniel Gomez Rico Nov 15 '17 at 23:08
5

When a user hits your site, identify them with a unique id and save it in a cookie if they don't already have one, then use the Mixpanel Identify API call to identify them. You can persist the unique id to your database in the user's record once they have registered, so you can re-set it in the case they clear their cookies.

If the user clears their cookies before registering, then you would be out of luck, but that's the nature of this beast and would be an issue anywhere.

x1a4
  • 19,417
  • 5
  • 40
  • 40
  • Woody Schneider works @ mixpanel and provides a couple insights to the platform. I awarded the answer there, as he is an authoritative source for the how mixpanel actually works. Thanks for your response, though - it's the one we ended up implementing. – Jim Rubenstein May 24 '12 at 12:17
  • 1
    Any chance you have an example of the code you ended up implementing? – RichLitt Oct 17 '14 at 18:41