Question

I am setting Mixpanel up, and I found out that if I log in with a user (and identify that user), log out and then re-register as a new user, the new user's details overwrite the previously logged in user (presumably when I call alias). How can I tell mixpanel that a user has logged out and to reset the identity token (make it anonymous again)?

Was it helpful?

Solution 2

It was released on Mixpanel Javascript version v2.8.0 the mixpanel.reset() function, so that's officially what should be called on user logout. See https://github.com/mixpanel/mixpanel-js/issues/67 .

OTHER TIPS

I ran into the same issue, and after some sleuthing I discovered that you can manually clear the mixpanel cookies with mixpanel.cookie.clear().

However, you need to make sure that the mixpanel library has loaded, so I ended up putting it in a stupid timeout:

var id = window.setInterval(function() {
  if (mixpanel.cookie && mixpanel.cookie.clear) {
    mixpanel.cookie.clear();
    window.clearInterval(id);
  }
}, 50);

And then, since I didn't want to do this on every page, I added a query string parameter onto my logout redirect URL. So after visiting /logout it would redirect them to /home?_ref=logout, at which point I would clear the mixpanel cookie only if that query string parameter existed.

It was pretty annoying, but it seemed to work.

for android on logout you can use this MixpanelAPI.reset()

  1. Call clearSuperProperties() to remove any Super Properties in local storage.
  2. Set new_distinct_id = UUID.randomUUID().toString());
  3. Call .identify(new_distinct_id) and .getPeople().identify(new_distinct_id)

This should wipe the device clean for a fresh user that can then register and be aliased to another distinct_id.

The best way to do this with javascript is to delete the cookie. The name of the cookie is mp_{mixpanel_token_id}_mixpanel

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top