Checking if a “distinct_id” already exists in Mixp

2019-08-01 22:04发布

问题:

Is there a way to check to see if a previous "distinct_id" already exists in Mixpanel with Javascript?

I am currently having an issue where once someone moves through my onboarding process and all the events are tracked, if they log out and log back in it is creating a separate record in the "explore" section of the admin interface.

I want to be able to throw some logic around my initial login event to make sure to check if the "Distinct_id" already has been used, and then tie the login event to that same user instead of creating a brand new one in Mixpanel.

回答1:

It would be great to see your code, but I can guess the following answer based on my experience:

The first time you create a people profile, you should create it executing mixpanel.alias(YOUR_DISTINCT_ID) instead of mixpanel.identify(). This will associate the mixpanel internal distinct_id with your custom distinct id (for instance: an email address, an username, etc).

Next time the user lands on a different page, you call mixpanel.identify(YOUR_DISTINCT_ID).

Doing so, if the user logs out, and then logs in back, calling mixpanel.identify(YOUR_DISTINCT_ID) will be enough, Mixpanel is going to associate your custom id with the original one avoiding duplicated profiles.