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

116
Vistas
Eventlistener fires too many GA4 events

I used to have a eventlistener that looks something like this:

<script>document.querySelectorAll('.myclass').forEach(item => {
  item.addEventListener('click', event => {

gtag('event', 'phoneclick', {
  'event_category' : 'contact',
  'event_label' : 'phone'
});
});
})</script>

Somehow it fires the event two times. First I thought it was because the class was used more than once. But actually the class is only used for one element on the page.

I am new to this topic, so a beginners-guide would help me a big deal! Thank you very much.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

  1. Using gtag to send events is not the best practice. I would suggest getting rid of your whole event listener with whatever's inside and use GTM to properly track events.
  2. How did you check that the event fires twice? Show a network tab screenshot. As well as a dataLayer screenshot.
  3. Do some proper debugging: add a console.log to the callback, see if it fires twice too.
  4. Use preventDefault and stopPropagation. Also try looking for existing answers: Javascript click event firing twice, even with stopPropagation
about 4 years ago · Juan Pablo Isaza Denunciar

0

If the element .myclass only has one at the page, maybe try add a event listener as this,

document.querySelector('.myclass').addEventListener("click", function() { 

gtag('event', 'phoneclick', {
  'event_category' : 'contact',
  'event_label' : 'phone'
});

});
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