Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset Mixpanel before init #417

Open
levrik opened this issue Feb 13, 2024 · 0 comments
Open

Reset Mixpanel before init #417

levrik opened this issue Feb 13, 2024 · 0 comments

Comments

@levrik
Copy link

levrik commented Feb 13, 2024

I need to reset Mixpanel (mixpanel.reset()) when a redirect to login is triggered due to an expired session. As I only initialize Mixpanel for authenticated users, the call to mixpanel.reset() fails as it runs before mixpanel.init(...) in this case.

That's how I currently work around this limitation by resetting Mixpanel immediately after initialization if the user ID has changed from what Mixpanel persisted.

mixpanel.init(token);

const previousUserId = mixpanel.get_distinct_id();
if (previousUserId && previousUserId !== userInfo.id) {
  mixpanel.reset();
}

mixpanel.identify(userInfo.id);

// @ts-expect-error: Private API
mixpanel._init_url_change_tracking('url-with-path');

I think it would be very useful to be able to call mixpanel.reset() also without having called mixpanel.init(...) before. That way I could simply do the reset whenever the code triggers a redirect to the external login page.

As you can see there's also another workaround towards the end to delay the SPA pageview tracking to prevent Mixpanel from tracking a pageview with a persisted outdated user ID.

If you have an idea to better solve this with current functionality, let me know.

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

No branches or pull requests

1 participant