mixpanel / mixpanel-node

A node.js API for mixpanel
http://www.mixpanel.com
MIT License
476 stars 159 forks source link

Mixpanel multiple aliasing #155

Open Msarnaot opened 5 years ago

Msarnaot commented 5 years ago

Hi Mixpanel Team,

We have recently started using this module and its been great so far, however I'm a little unclear regarding the alias method. Our scenario includes users coming multiple times to our product and can perform multiple actions before signing up or logging in.

If a user comes on first time, and they are not logged in I send a random distinct_id with all events on the server, once they do signup we call the alias method with their email, and all subsequent track calls will use their email address as the distinct_id not the original random distinct_id.

If the user comes on next week and they are not logged in, we do the same thing and track all events with a random distinct id, but then once they login I can send their email as the distinct_id, however do I alias again on their login to attach them to the new random ID that was being used on this second visit? The docs discourage multiple aliasing however it's unclear how to handle multiple random distinct_ids from different non logged-in sessions.

Ahh42 commented 4 years ago

Hello mates,

The use case outlined above by @Msarnaot is very intuitive. When we use "identify", we will be tracking all activity while the user is known + the activity when unknown related to the distinct ID which was aliased the first time.

But what if the user comes UNKNOWN another time from a different device. According to your documentation, we cannot alias him again to map another distinct ID. So here, all following activity while he is unknown with a distinct ID different than the aliased one, would be impossible to track??

Could you please confirm this? or is there a workaround?

HerrNiklasRaab commented 2 years ago

Same question here :)

sergey-shpak commented 2 years ago

Same scenario:

  1. user visits our website and we are setting random distinct id to track actions
  2. user signs in and we alias distinct id with user email
  3. user uses new device and we are setting another distinct id
  4. users signs in on new device - the problem - how to link with previous distinct id ???

cc: @tdumitrescu, @jaredmixpanel, @carlsverre

sergey-shpak commented 2 years ago

if I got it right, this has to be solved with $identify, something like:

  1. on any action - track('someAction', {distinct_id: 'user-distinct-uuidv4-num1'})
  2. on user sign in - track('$identify', {$identified_id: 'userId', $anon_id: 'user-distinct-uuidv4-num1'})
  3. and then on new device track new distinct_id - track('someAction', {distinct_id: 'user-distinct-uuidv4-num2'})
  4. and on user sign in - track('$identify', {$identified_id: 'userId', $anon_id: 'user-distinct-uuidv4-num2'})

*distinct_id has to be uuid v4

sergey-shpak commented 2 years ago

ok, so after small test everything works as described:

// new device random distinct_id1 uuid v4
await track('TestAction', {distinct_id: distinct_id1})
// and then identify distinct_id1 with userId
await track('$identify', {$identified_id: userId, $anon_id: distinct_id1})
// new device random distinct_id2 uuid v4
await track('TestAction2', {distinct_id: distinct_id2})
// and then identify distinct_id2 with userId
await track('$identify', {$identified_id: userId, $anon_id: distinct_id2})

as result distinct_id1, distinct_id2, userId are merged into single identity and can be tracked :rocket: :rocket: :rocket: *to mention, project settings merge id has to be enabled

sergey-shpak commented 2 years ago

asking questions and solving right in place - that is how we do it :nerd_face: now would be nice to get mixpanel GROWTH plan for free :wink: and the issue can be closed