[{"data":1,"prerenderedAt":522},["ShallowReactive",2],{"rule-duplicate-event-listeners":3},{"id":4,"title":5,"body":6,"breadcrumb":486,"coderail":493,"dateModified":512,"datePublished":512,"description":513,"extension":514,"meta":515,"navigation":195,"next":512,"path":516,"prev":512,"schemaType":517,"seo":518,"stem":519,"wide":520,"__hash__":521},"docs\u002Frules\u002Fduplicate-event-listeners.md","Duplicate event listeners across tags",{"type":7,"value":8,"toc":478},"minimark",[9,16,54,59,66,70,77,81,345,349,384,388,446,450,474],[10,11,12],"p",{},[13,14,15],"strong",{},"Summary",[17,18,19,30,36,42,48],"ul",{},[20,21,22,25,26],"li",{},[13,23,24],{},"rule_id"," — ",[27,28,29],"code",{},"duplicate-event-listeners",[20,31,32,35],{},[13,33,34],{},"purpose"," — Detect multiple Custom HTML tags registering listeners for the same DOM event",[20,37,38,41],{},[13,39,40],{},"effect"," — Duplicate event firing, inflated dataLayer pushes, and unnecessary JS execution on every interaction",[20,43,44,47],{},[13,45,46],{},"layer"," — container",[20,49,50,53],{},[13,51,52],{},"reversibility"," — non-destructive",[55,56,58],"h2",{"id":57},"what-fires-this","What fires this",[10,60,61,62,65],{},"The rule reads ",[27,63,64],{},"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.",[55,67,69],{"id":68},"why-it-matters","Why it matters",[10,71,72,73,76],{},"Each registered listener fires independently on every matching event. Two tags both listening for ",[27,74,75],{},"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.",[55,78,80],{"id":79},"example","Before \u002F after",[82,83,84,263],"compare",{},[85,86,88],"compare-col",{"label":87},"Before — flagged",[89,90,95],"pre",{"className":91,"code":92,"language":93,"meta":94,"style":94},"language-js shiki shiki-themes github-light github-dark","\u002F\u002F Tag A — GA4 form tracking\ndocument.addEventListener('click', function(e) {\n  if (e.target.matches('button[type=\"submit\"]')) {\n    dataLayer.push({ event: 'form_submit_ga4' })\n  }\n})\n\n\u002F\u002F Tag B — HubSpot form tracking (separate tag)\ndocument.addEventListener('click', function(e) {\n  if (e.target.matches('button[type=\"submit\"]')) {\n    dataLayer.push({ event: 'form_submit_hs' })\n  }\n})\n","js","",[27,96,97,106,140,160,178,184,190,197,203,224,239,253,258],{"__ignoreMap":94},[98,99,102],"span",{"class":100,"line":101},"line",1,[98,103,105],{"class":104},"sJ8bj","\u002F\u002F Tag A — GA4 form tracking\n",[98,107,109,113,117,120,124,127,131,133,137],{"class":100,"line":108},2,[98,110,112],{"class":111},"sVt8B","document.",[98,114,116],{"class":115},"sScJk","addEventListener",[98,118,119],{"class":111},"(",[98,121,123],{"class":122},"sZZnC","'click'",[98,125,126],{"class":111},", ",[98,128,130],{"class":129},"szBVR","function",[98,132,119],{"class":111},[98,134,136],{"class":135},"s4XuR","e",[98,138,139],{"class":111},") {\n",[98,141,143,146,149,152,154,157],{"class":100,"line":142},3,[98,144,145],{"class":129},"  if",[98,147,148],{"class":111}," (e.target.",[98,150,151],{"class":115},"matches",[98,153,119],{"class":111},[98,155,156],{"class":122},"'button[type=\"submit\"]'",[98,158,159],{"class":111},")) {\n",[98,161,163,166,169,172,175],{"class":100,"line":162},4,[98,164,165],{"class":111},"    dataLayer.",[98,167,168],{"class":115},"push",[98,170,171],{"class":111},"({ event: ",[98,173,174],{"class":122},"'form_submit_ga4'",[98,176,177],{"class":111}," })\n",[98,179,181],{"class":100,"line":180},5,[98,182,183],{"class":111},"  }\n",[98,185,187],{"class":100,"line":186},6,[98,188,189],{"class":111},"})\n",[98,191,193],{"class":100,"line":192},7,[98,194,196],{"emptyLinePlaceholder":195},true,"\n",[98,198,200],{"class":100,"line":199},8,[98,201,202],{"class":104},"\u002F\u002F Tag B — HubSpot form tracking (separate tag)\n",[98,204,206,208,210,212,214,216,218,220,222],{"class":100,"line":205},9,[98,207,112],{"class":111},[98,209,116],{"class":115},[98,211,119],{"class":111},[98,213,123],{"class":122},[98,215,126],{"class":111},[98,217,130],{"class":129},[98,219,119],{"class":111},[98,221,136],{"class":135},[98,223,139],{"class":111},[98,225,227,229,231,233,235,237],{"class":100,"line":226},10,[98,228,145],{"class":129},[98,230,148],{"class":111},[98,232,151],{"class":115},[98,234,119],{"class":111},[98,236,156],{"class":122},[98,238,159],{"class":111},[98,240,242,244,246,248,251],{"class":100,"line":241},11,[98,243,165],{"class":111},[98,245,168],{"class":115},[98,247,171],{"class":111},[98,249,250],{"class":122},"'form_submit_hs'",[98,252,177],{"class":111},[98,254,256],{"class":100,"line":255},12,[98,257,183],{"class":111},[98,259,261],{"class":100,"line":260},13,[98,262,189],{"class":111},[85,264,266],{"label":265},"After — fixed",[89,267,269],{"className":91,"code":268,"language":93,"meta":94,"style":94},"\u002F\u002F Tag A — central listener only\ndocument.addEventListener('click', function(e) {\n  if (e.target.matches('button[type=\"submit\"]')) {\n    dataLayer.push({ event: 'form_submit' })\n  }\n})\n\n\u002F\u002F Tag B fires on GTM Custom Event trigger \"form_submit\"\n\u002F\u002F No addEventListener in Tag B\n",[27,270,271,276,296,310,323,327,331,335,340],{"__ignoreMap":94},[98,272,273],{"class":100,"line":101},[98,274,275],{"class":104},"\u002F\u002F Tag A — central listener only\n",[98,277,278,280,282,284,286,288,290,292,294],{"class":100,"line":108},[98,279,112],{"class":111},[98,281,116],{"class":115},[98,283,119],{"class":111},[98,285,123],{"class":122},[98,287,126],{"class":111},[98,289,130],{"class":129},[98,291,119],{"class":111},[98,293,136],{"class":135},[98,295,139],{"class":111},[98,297,298,300,302,304,306,308],{"class":100,"line":142},[98,299,145],{"class":129},[98,301,148],{"class":111},[98,303,151],{"class":115},[98,305,119],{"class":111},[98,307,156],{"class":122},[98,309,159],{"class":111},[98,311,312,314,316,318,321],{"class":100,"line":162},[98,313,165],{"class":111},[98,315,168],{"class":115},[98,317,171],{"class":111},[98,319,320],{"class":122},"'form_submit'",[98,322,177],{"class":111},[98,324,325],{"class":100,"line":180},[98,326,183],{"class":111},[98,328,329],{"class":100,"line":186},[98,330,189],{"class":111},[98,332,333],{"class":100,"line":192},[98,334,196],{"emptyLinePlaceholder":195},[98,336,337],{"class":100,"line":199},[98,338,339],{"class":104},"\u002F\u002F Tag B fires on GTM Custom Event trigger \"form_submit\"\n",[98,341,342],{"class":100,"line":205},[98,343,344],{"class":104},"\u002F\u002F No addEventListener in Tag B\n",[55,346,348],{"id":347},"remediation","Remediation",[350,351,352,355,358,368,374,381],"ol",{},[20,353,354],{},"Open the rule finding and note which DOM events are registered across multiple tags.",[20,356,357],{},"For each duplicated event type, designate one tag as the listener. Its sole job is to detect the event and push to the dataLayer.",[20,359,360,361,363,364,367],{},"Replace that tag's handler with a single ",[27,362,116],{}," call that fires ",[27,365,366],{},"dataLayer.push({ event: 'your_event_name' })",".",[20,369,370,371,373],{},"Remove the ",[27,372,116],{}," calls from all other tags that duplicated the listener.",[20,375,376,377,380],{},"Convert those tags to fire on a GTM Custom Event trigger matching the ",[27,378,379],{},"event"," value pushed in step 3.",[20,382,383],{},"Test in Preview mode that the event fires exactly once per user interaction and that all dependent tags receive it.",[55,385,387],{"id":386},"metadata","Metadata",[389,390,393,394,399,393,403,407,393,410,414,393,417,420,393,423,427,393,430,434,393,440,443],"dl",{"className":391},[392],"spec-list","\n  ",[395,396,398],"dt",{"id":397},"severity","Severity",[400,401,402],"dd",{},"medium",[395,404,406],{"id":405},"tier","Tier",[400,408,409],{},"optimization",[395,411,413],{"id":412},"category","Category",[400,415,416],{},"quality",[395,418,419],{"id":46},"Layer",[400,421,422],{},"container",[395,424,426],{"id":425},"version","Version",[400,428,429],{},"1",[395,431,433],{"id":432},"effort","Effort",[400,435,436,439],{},[27,437,438],{},"2hr"," (about 2 hours)",[395,441,442],{"id":52},"Reversibility",[400,444,445],{},"non-destructive",[55,447,449],{"id":448},"see-also","See also",[17,451,452,460,467],{},[20,453,454,459],{},[455,456,458],"a",{"href":457},"\u002Fcategories\u002Fquality\u002F","Quality rules"," — other rules in this category",[20,461,462,466],{},[455,463,465],{"href":464},"\u002Fhealth-score\u002F","Health score"," — how this rule contributes to the score",[20,468,469,473],{},[455,470,472],{"href":471},"\u002Frules\u002F","Rules catalog"," — browse all rules",[475,476,477],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":94,"searchDepth":108,"depth":108,"links":479},[480,481,482,483,484,485],{"id":57,"depth":108,"text":58},{"id":68,"depth":108,"text":69},{"id":79,"depth":108,"text":80},{"id":347,"depth":108,"text":348},{"id":386,"depth":108,"text":387},{"id":448,"depth":108,"text":449},[487,490,492],{"label":488,"href":489},"API Reference","\u002F",{"label":491,"href":471},"Rules",{"label":29},{"cards":494,"onpage":506},[495],{"title":496,"tabs":497},"Evaluate",[498,502],{"label":499,"language":500,"code":501},"cURL","bash","curl https:\u002F\u002Fdeveloper.tagmanifest.com\u002Fv1\u002Fevaluate-rule \\\n  -H \"Authorization: Bearer $TM_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"rule_id\":\"duplicate-event-listeners\",\"url\":\"https:\u002F\u002Fexample.com\"}'\n",{"label":503,"language":504,"code":505},"MCP","text","User: Run duplicate-event-listeners on https:\u002F\u002Fexample.com\n\n# Tool call\n{\n  \"tool\": \"evaluate_rule\",\n  \"arguments\": {\n    \"rule_id\": \"duplicate-event-listeners\",\n    \"url\": \"https:\u002F\u002Fexample.com\"\n  }\n}\n",[507,508,509,510,511],{"id":57,"label":58},{"id":68,"label":69},{"id":79,"label":80},{"id":347,"label":348},{"id":386,"label":387},null,"Multiple custom HTML tags add listeners for the same DOM events, which can cause race conditions and double-firing.","md",{},"\u002Frules\u002Fduplicate-event-listeners","TechArticle",{"title":5,"description":513},"rules\u002Fduplicate-event-listeners",false,"CKFCBD1NYcIbUijD3IuOIdoz_3JWzU0Kotgkb_O5wiw",1796069484228]