WarningGTMGoogle Tag Manager

Invalid CSS Selectors in Triggers

CL
By Christopher LandaverdeCreator of AdLint · ad-tech tracking specialistUpdated

Why It Matters

GTM's Click and Element Visibility triggers accept a CSS selector as their match target (Click Element matches CSS selector). The browser evaluates the selector against the DOM at trigger time. If the selector is malformed. button[data-id="cta] with an unclosed quote, .cta:hov with a typo in the pseudo-class. The browser throws an error and the trigger fails to match. The tag wired to that trigger never fires, and the audit dashboard shows it as "passed" because no errors were logged. The most common pattern is a copy-paste from a developer Slack message where the selector was abbreviated or wrapped, breaking the syntax. AdLint validates the selector syntax statically; the check is high-signal because invalid selectors are nearly always bugs, not intentional configurations.

How To Fix It

  1. AdLint's details list each affected trigger and its invalid selector.

  2. Open each trigger in GTM and inspect the selector field.

  3. Validate the selector. Paste it into your browser's DevTools console: document.querySelector("your-selector-here"). If it throws, the syntax is broken.

  4. Common fixes: balance quotes and brackets, escape colons and other special characters in attribute values ([data-test="user\:profile"]), and check pseudo-class spelling (:hover not :hov).

  5. After fixing, complete a test interaction in Preview mode and confirm the trigger now matches. Publish.

Example

Configuration
Invalid: button[data-cta="signup
Fixed: button[data-cta="signup"]

Invalid: .nav-link:hov
Fixed: .nav-link:hover
For Your Client Report

Invalid CSS selectors in one or more GTM Click or Element Visibility triggers. The W3C Selectors specification, browsers reject malformed selectors at evaluation time, causing the trigger to never match. Tags wired to these triggers fail to fire without surfacing any error, producing dead measurement paths invisible in standard reporting. Fix: validate each flagged selector against the live DOM using document.querySelector and fix syntax errors. Source: developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors.

Drop this paragraph into your client deliverable. Sources back to the canonical platform documentation linked below.

References