Skip to main content
TagManifest /Docs Dashboard

Duplicate event listeners across tags

Multiple custom HTML tags add listeners for the same DOM events, which can cause race conditions and double-firing.

On this page 6

Summary

  • rule_id — duplicate-event-listeners
  • purpose — Detect multiple Custom HTML tags registering listeners for the same DOM event
  • effect — Duplicate event firing, inflated dataLayer pushes, and unnecessary JS execution on every interaction
  • layer — container
  • reversibility — non-destructive

What fires this

The rule reads codeAnalysis.eventListeners from each active, non-paused Custom HTML tag. It builds a map from event name to the list of tags that register that listener. Within a single tag, each event type is counted once — a tag registering the same event twice in its own code does not self-flag. The rule fires when any event type appears in two or more distinct tags.

Why it matters

Each registered listener fires independently on every matching event. Two tags both listening for submit each push to the dataLayer on the same form submission — downstream tags receive two pushes and fire twice. This inflates event counts, distorts conversion reports, and adds JavaScript execution cost on every interaction. GTM's built-in trigger system exists specifically to centralize event detection: one listener, many tags.

Before / after

// Tag A — GA4 form tracking
document.addEventListener('click', function(e) {
  if (e.target.matches('button[type="submit"]')) {
    dataLayer.push({ event: 'form_submit_ga4' })
  }
})

// Tag B — HubSpot form tracking (separate tag)
document.addEventListener('click', function(e) {
  if (e.target.matches('button[type="submit"]')) {
    dataLayer.push({ event: 'form_submit_hs' })
  }
})
// Tag A — central listener only
document.addEventListener('click', function(e) {
  if (e.target.matches('button[type="submit"]')) {
    dataLayer.push({ event: 'form_submit' })
  }
})

// Tag B fires on GTM Custom Event trigger "form_submit"
// No addEventListener in Tag B

Remediation

  1. Open the rule finding and note which DOM events are registered across multiple tags.
  2. For each duplicated event type, designate one tag as the listener. Its sole job is to detect the event and push to the dataLayer.
  3. Replace that tag's handler with a single addEventListener call that fires dataLayer.push({ event: 'your_event_name' }).
  4. Remove the addEventListener calls from all other tags that duplicated the listener.
  5. Convert those tags to fire on a GTM Custom Event trigger matching the event value pushed in step 3.
  6. Test in Preview mode that the event fires exactly once per user interaction and that all dependent tags receive it.

Metadata

Severity
medium
Tier
optimization
Category
quality
Layer
container
Version
1
Effort
2hr (about 2 hours)
Reversibility
non-destructive

See also

Examples

Evaluate
curl https://developer.tagmanifest.com/v1/evaluate-rule \
  -H "Authorization: Bearer $TM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rule_id":"duplicate-event-listeners","url":"https://example.com"}'