Skip to content

Conversation

alexs-mparticle
Copy link
Collaborator

@alexs-mparticle alexs-mparticle commented Oct 25, 2023

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

  • A bug was recently encountered where an anonymous profiles were not being merged with identified profiles in Mixpanel
  • This issue is attributed to the way mParticle handles anonymous users versus how Mixpanel handles them.
    • mParticle assigns all users a unique MPID, even if they are anonymous
    • Mixpanel uses a device_id to denote an anonymous user and a user_id for known users, and a third, distinct_id to bridge the gap.
  • When mParticle identifies an anonymous user, we currently send that MPID to Mixpanel's identify function as part of our Identify Request Callback. Mixpanel treats this MPID as the user's user_id, linking it with the user's device_id, and associates future events with the anonymous MPID as Mixpanel's distinct_id.
  • When mParticle then later identifies the user as a known user via a login or a subsequent identity request, it sends a new MPID to Mixpanel.identify as a user_id, but Mixpanel generates an error $anon_distinct_id didn't match expected GUID pattern and does not associate future events with the previous user_id.
  • This fix now will verify that an mParticle Identify request will not generate a Mixpanel identify request unless there is an actual mParticle user identity, denoting that the user is actually known. If the user is anonymous, mParticle will continue to associate events with the anonymous MPID, and will continue to forward events to Mixpanel, which will use their device_id to track anonymous events.
  • Once the user is correctly identified via mParticle as a known user, we will then send a request to Mixpanel's Identify function with an actual user_id that is known, allowing Mixpanel to correctly merge the profiles.
  • In this fix, we are also including an implementation of Mixpanel's reset method tied to mParticle's logout method, so that if a user formally logs out, their session is logged out via Mixpanel as per their requirements.
    • As per Mixpanel's Identifying Users documentation, the recommended action is to call reset() on logout, so we are splitting logout from the other Identity methods so that logout properly triggers a reset().

Testing Plan

  • Was this tested locally? If not, explain why.
  • Set up a sample app with the Mixpanel Kit configured to use MPID as the External Identity Type
    Screenshot 2023-10-25 at 6 07 42 PM
  • Send anonymous events and then perform a login.
  • Continue to fire events as a logged in user, and then log out.
  • Send more anonymous events, and then log back in as the same user.
  • You should no longer receive the initial error in the identify calls, and all events should be tied to the same user

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

@alexs-mparticle alexs-mparticle marked this pull request as ready for review October 25, 2023 22:09
@alexs-mparticle alexs-mparticle force-pushed the fix/SQDSDKS-5895-merging-profiles branch from 5218ee3 to a4a7bfd Compare October 27, 2023 17:07
Copy link
Collaborator

@rmi22186 rmi22186 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly changes to comments to clarify further. Some requests in the tests to include MPID as a test option. It wouldn't need to be in the array/for each, and could be its standalone test.

@alexs-mparticle alexs-mparticle merged commit 391517d into development Oct 31, 2023
github-actions bot pushed a commit that referenced this pull request Oct 31, 2023
## [2.1.1](v2.1.0...v2.1.1) (2023-10-31)

### Bug Fixes

* Split out logout function from onUserIdentified ([#45](#45)) ([391517d](391517d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants