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)?
Logging out helps prevent other users from accessing the system without verifying their credentials. It also helps protect the current user's access or prevent unauthorized actions on the current login session and is thus an important part of security.
Logout is a noun, to be used like so: "go to the logout screen". Log out is an action, to be used like so: "you need to log out". Because both are action buttons, they need to both be titled "Log Out."
Quick tip: You can also use the Ctrl + Shift + Esc keyboard shortcut to open Task Manager. Click the Users tab. Right-click the user and select the Sign off option.
Alternatively referred to as log, log off, and sign out, sign off is disconnecting from a network or account voluntarily. For example, to check your credit card balance, you log into your account. When you are done reviewing the information, you log out, which is the same as signing off.
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.
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 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With