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

195
Vistas
How can I add a GTM event handler on a button using React or Next?

In my Next app, I am using react-gtm-module with GTM ID. Now I want an event handler on the button so that when it is clicked, an event should be added to the Google Tag Manager data layer.

export const MyButton = () => (
  <button
    onClick={() => {
      window.dataLayer.push({ event: "some-event" });
    }}
  >
    Click Me!
  </button>
);

But it is giving me the error "Type error: Property 'dataLayer' does not exist on type 'Window & type of globalThis'."

In _app.tsx I have initialized GTM with the following code:

import type { AppProps } from "next/app";
import { useEffect } from "react";
import TagManager from "react-gtm-module";

function MyApp({ Component, pageProps }: AppProps) {
  useEffect(() => {
    TagManager.initialize({
      gtmId: "GTM-XXXXXXX",
      events: {
        sendUserInfo: "userInfo",
      },
      dataLayer: {
        userId: "001",
        userProject: "project",
      },
    });
  }, []);
return <Component {...pageProps} />;
}

export default MyApp;
about 4 years ago · Juan Pablo Isaza
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