Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda