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)?

- 2,715
- 6
- 27
- 50

- 32,953
- 42
- 145
- 236
4 Answers
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.

- 2,562
- 20
- 15
-
5For those with a single page app where you may never refresh, be sure to re-initialize immediately after you clear your cookies. `mixpanel.cookie.clear(); mixpanel.init("GARBAGE");` – kevinnuut Mar 03 '15 at 23:51
-
To be 100% sure Mixpanel loaded, you can use the `loaded` option in the `init` where you pass a function for it to run after it loads: `mixpanel.init("YOUR_TOKEN", { "loaded": function() { ... your clear code goes here ... } } );` – Anton Jun 12 '15 at 12:28
-
@kevinnuut why do we need to reinitialize again ? – gaurav5430 Sep 07 '21 at 07:25
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 .

- 508
- 4
- 12
- Call
clearSuperProperties()
to remove any Super Properties in local storage. - Set
new_distinct_id = UUID.randomUUID().toString());
- 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

- 5,203
- 4
- 40
- 47

- 638
- 4
- 14