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

115
Views
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 answers
Answer question

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 Report

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 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!