Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
Mixpanel using Google Tag Manager and React JS

I am trying to implement Mixpanel with my React App using Google Tag Manager. I have successfully integrated it using GTM but I have trouble with mixpanel always being undefined on reload. I am using CDN for it.

If I go onto some other page and come back to the page where I am using Mixpanel, there's no error. So I diagnosed that as it is an asynchronous operation it takes some time to load mixpanel in my app. So I tried using the useEffect hook and useState but it failed to solve my problem.

Below is my code:

const [mixpanelLoad, setMixpanelLoad] = useState(false);

  useEffect(()=>{
    console.log('IN USEEFFECT');
    console.log(mixpanel);
    if (mixpanel) {
    // It never comes here on first reload
      setMixpanelLoad(true);
      console.log('MIXPANEL LOADED');
    }
    if (mixpanelLoad) {
    // thus it never does the tracking 
      console.log('DOING TRACKING');
      mixpanel.track('Track Bill Page');
    }
  }, [mixpanelLoad]);

On first reload it always says that mixpanel is undefined.

I am using CDN so I don't have to use any mixpanel library.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Certain methods/features can only be used after the Mixpanel library has finished loading. init() has a loaded function available to handle this automatically -

mixpanel.init('YOUR PROJECT TOKEN', {
    loaded: function(mixpanel) {
        distinct_id = mixpanel.get_distinct_id();
    }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!