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

track_links does not work in a React app unless wrapped in a useEffect + setTimeout #419

Open
nicolassanmar opened this issue Feb 19, 2024 · 0 comments

Comments

@nicolassanmar
Copy link

nicolassanmar commented Feb 19, 2024

Hey, I want to track some links that lead to external websites using the mixpanel.track_links method. Unfortunately this causes the app to break unless mixpanel.track_links is called within a useEffect (which makes sense) and a setTimeout (which I don't understand).

I want to track the links this way (not using track and using onClick to redirect) because I also want to use the Next.js feature that allows you to prefetch links.

I created a minimal repo reproducing this issue here: https://github.com/nicolassanmar/mixpanel-track-links-next-reproduction
It throws errors when you call track_links using either a ref or the element's id if you don't call it using a timeout:

image

I don't think this is related to the initialization of Mixpanel, since in the reproduction I initialize Mixpanel and then navigate to the page that does not use a setTimeout and it fails

The same issue can be replicated with mixpanel.track_forms

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