Identity Management: Best Practices

You can use mixpanel.alias() and mixpanel.identify() methods to keep the identity of your users consistent throughout their interactions in your site or app.

The correct implementation of these methods permits you to use your own user IDs, without breaking your Mixpanel reports (particularly Funnels).

Manage Identity with Alias and Identify Methods

An ideal integration enables you to track the actions of your users across your site or app. An example of a typical user journey would be if a user first engages your site anonymously, decides to signup, and logs in later.

Mixpanel provides two methods to let you track those actions;

  1. When a new user signs up, call mixpanel.alias("YOUR_USER_ID") once.
  2. When a user logs in, call mixpanel.identify("YOUR_USER_ID").

Here’s an example of how alias and identify work together to manage user identity:

  • Sally comes to your website for the first time. Mixpanel assigns Sally a randomly generated ID, which is known as a Mixpanel distinct_id.
  • Mixpanel assigns Sally the distinct_id “12345”. Now all her actions are tied to that distinct_id.
  • After clicking through a few pages, she successfully signs up for an account.
  • The signup confirmation page calls the mixpanel.alias() method and passes Sally’s email address as an argument. For example, mixpanel.alias(“sally@gmail.com").
  • The mixpanel.alias(“sally@gmail.com”) method doesn't change her Mixpanel distinct_id.  It adds the ID "sally@gmail.com" to a Mixpanel lookup table and maps it to the original Mixpanel distinct_id “12345”.
  • Now Mixpanel calls the mixpanel.identify("sally@gmail.com") method and passes the ID ("sally@gmail.com") to all subsequent pages and logins whenever Mixpanel sees data for "sally@gmail.com”.
  • Mixpanel remaps her original distinct_id of “12345”. So all actions Sally takes–whether on your site, in your app, or anonymously before she signed up for her account–maps to her.

    The image below illustrates the identity management process.

 

2016-06-17_21_58_29.646304-alias_identify_graphic.png

 

Avoid Calling mixpanel.alias() on a User More Than Once

An alias can only point to one Mixpanel distinct_id.

If you’ve already mapped “sally@gmail.com” to Mixpanel distinct_id “12345”, any attempt to map sally@gmail.com to Mixpanel distinct_id 67890 fails.

In the previous example, Sally came to your website. Suppose she decides to download your app on her phone and logs in. The mixpanel.alias() method does not work here. Even though Sally has not used your app on this device before, she is not a new user.

If Mixpanel calls the mixpanel.alias() method, it would attempt to map the email to the random Mixpanel distinct_id from the phone. To remedy this scenario, add the mixpanel.identify() method to associate the original Mixpanel distinct_id “12345”, where all Sally’s actions are already stored.

Server-side aliasing

If an identify or track call arrives to Mixpanel with a new distinct_id too quickly after an alias call, a race condition occurs between the event and the alias call.

Usually there are no issues when your identify and track calls arrive ~1 second after the alias. When the alias queue is backed up, Mixpanel queues events as well, alleviating the race condition.

Split or duplicate profiles can result when events are processed before their corresponding alias. To mitigate split or duplicate profiles, Mixpanel’s client-side Javascript library continues to send track calls to the original Mixpanel distinct_id while the records update.

Help Center Resources to Manage User Identities

Developer Documentation Resources to Manage User Identities

Is this article helpful?
6 out of 11 found this helpful

Comments

0 comments

Article is closed for comments.