{"id":99845,"date":"2025-02-20T17:30:55","date_gmt":"2025-02-20T17:30:55","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/css-selector-guide-for-google-tag-manager\/"},"modified":"2025-02-20T17:30:55","modified_gmt":"2025-02-20T17:30:55","slug":"css-selector-guide-for-google-tag-manager","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=99845","title":{"rendered":"CSS Selector Guide For Google Tag Manager"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"&quot;author&quot;\">. Since it has the <code>id<\/code> attribute, it\u2019s a reasonable expectation that it\u2019s the <strong>only<\/strong> such element on the page, thus even that short selector is very powerful.<\/p>\n<p>On the other hand, sometimes all you can do is use a really long, complex chain, because there are so few uniquely identifying features in the element itself or its closest ancestors. Thus, the selector might end up looking like this:<\/p>\n<p><code>#main &gt; article &gt; div.post-content.markdown &gt; div &gt; p:nth-child(12) &gt; a:nth-child(2)<\/code><\/p>\n<p>It\u2019s not pretty, and it carries the additional weight that <strong>the longer and more complex the CSS selector is, the more fragile it becomes<\/strong>. The selector above will be invalidated when any one of the elements in the chain changes position or form.<\/p>\n<p>In other words, always strive to create a selector that is <strong>as simple as possible<\/strong> without compromising <strong>its accuracy to target the exact element you want<\/strong>.<\/p>\n<p>CSS selectors originated, surprise surprise, in Cascading Style Sheets (CSS). Style sheets are sets of rules and declarations that govern how HTML elements are displayed (and sometimes interacted with) on a web page. Here\u2019s what a typical style declaration might look like:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-css\" data-lang=\"css\"><span style=\"color:#1e90ff;font-weight:bold\">a<\/span>:<span style=\"color:#888\">hover<\/span>, <span style=\"color:#1e90ff;font-weight:bold\">a<\/span>:<span style=\"color:#888\">active<\/span> {\n    <span style=\"color:#00a\">text-decoration<\/span>: <span style=\"color:#00a\">none<\/span>;\n    <span style=\"color:#00a\">font-weight<\/span>: <span style=\"color:#00a\">bold<\/span>\n}<\/code><\/pre>\n<\/div>\n<p>The two items preceding the <code>{<\/code> and separated by a comma are the <strong>selectors<\/strong>, and the two rows contained within the curly braces are the <strong>declarations<\/strong>. This is how you would read the rule:<\/p>\n<ol>\n<li>Select all links (<code>a<\/code>) that are currently being hovered over by the mouse (<code>:hover<\/code>)<\/li>\n<li>AND select all links (<code>a<\/code>) that are currently being clicked by the mouse (<code>:active<\/code>)<\/li>\n<li>THEN remove all text decorations (e.g underline) from them<\/li>\n<li>AND set their font weight to <strong>bold<\/strong><\/li>\n<\/ol>\n<p>CSS is its own, wonderfully complex discipline in web design and development. There are so many weird and magnificent things you can do with it, from <a href=\"https:\/\/www.amberweinberg.com\/replacing-js-functionality-with-css-properties\/\">replacing JavaScript functionality<\/a> to running complex transitions <a href=\"https:\/\/www.smashingmagazine.com\/2012\/06\/play-with-hardware-accelerated-css\/\">using hardware acceleration<\/a>.<\/p>\n<p>Well, in this guide we\u2019ll try to be a bit more modest and focus on how CSS selectors can be used with Google Tag Manager\u2019s JavaScript to make the most out of triggers, tags, and variables, where selecting, querying, or parsing the <strong>correct element<\/strong> is of utmost importance.<\/p>\n<h2 id=\"css-selectors-in-javascript\">CSS selectors in JavaScript<\/h2>\n<p>In <strong>JavaScript<\/strong>, you\u2019ll often run into CSS selectors in two scenarios:<\/p>\n<ol>\n<li>\n<p>You need to <strong>retrieve<\/strong> a specific element or elements from the page.<\/p>\n<\/li>\n<li>\n<p>You need to check if a given element <strong>matches<\/strong> a CSS selector.<\/p>\n<\/li>\n<\/ol>\n<p>Both of these scenarios are very relevant in Google Tag Manager. Before we jump into how they work in GTM, let\u2019s take a look at JavaScript\u2019s handling of CSS selectors.<\/p>\n<h3 id=\"using-documentqueryselector-and-documentqueryselectorall\">Using <code>document.querySelector<\/code> and <code>document.querySelectorAll<\/code><\/h3>\n<p>The two JavaScript methods you\u2019ll most often use with CSS selectors are <code>document.querySelector(selector)<\/code> and <code>document.querySelectorAll(selector)<\/code>.<\/p>\n<p>The first <strong>returns the first element on the page that matches the given selector<\/strong>.<\/p>\n<p>The second <strong>returns a list of all the elements on the page that match the given selector<\/strong>.<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#aaa;font-style:italic\">\/\/ Get the first outbound link element on the page\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">var<\/span> firstOutbound = <span style=\"color:#0aa\">document<\/span>.querySelector(<span style=\"color:#a50\">'a:not([href=\"mydomain.com\"])'<\/span>);\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Get all the checked checkbox and radio button elements on the page\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">var<\/span> allChecked = <span style=\"color:#0aa\">document<\/span>.querySelectorAll(<span style=\"color:#a50\">'input[type=\"checkbox\"]:checked,input[type=\"radio\"]:checked'<\/span>);\n<\/code><\/pre>\n<\/div>\n<p>As you can see, the selector is passed as a <strong>string<\/strong> argument to the method.<\/p>\n<p>Remember that HTML elements are essentially objects, and just capturing them makes often little sense. Instead, you\u2019ll want to do something with those objects, such as parse some property from them.<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#aaa;font-style:italic\">\/\/ Get the first outbound link element on the page\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">var<\/span> firstOutbound = <span style=\"color:#0aa\">document<\/span>.querySelector(<span style=\"color:#a50\">'a:not([href=\"mydomain.com\"])'<\/span>);\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Push the URL of this outbound link into dataLayer\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#0aa\">window<\/span>.dataLayer.push({\n  firstOutboundLinkURL: firstOutbound.getAttribute(<span style=\"color:#a50\">'href'<\/span>)\n});\n<\/code><\/pre>\n<\/div>\n<p>In the example above, we use <code>document.querySelector<\/code> to fetch the first outbound link (i.e. link that does NOT have <code>mydomain.com<\/code> in its <code>href<\/code>), and then we push it into <code>dataLayer<\/code>.<\/p>\n<p>One thing to remember is that <code>document.querySelectorAll<\/code> doesn\u2019t return an <strong>array<\/strong> but rather a <code>NodeList<\/code>. This means that <strong>you can\u2019t use regular array methods<\/strong> with whatever the method returns. You\u2019ll have to resort to some workarounds if you, for example, want to <code>map()<\/code> all elements in the list to get a modified array as a result.<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#aaa;font-style:italic\">\/\/ Get ALL outbound links on the page\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">var<\/span> allOutbound = <span style=\"color:#0aa\">document<\/span>.querySelectorAll(<span style=\"color:#a50\">'a:not([href=\"mydomain.com\"])'<\/span>);\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Create an array of all their href values\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">var<\/span> allHrefValues = <span style=\"color:#0aa\">Array<\/span>.prototype.map.call(allOutbound, <span style=\"color:#00a\">function<\/span>(link) { <span style=\"color:#00a\">return<\/span> link.href; });\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Remove all duplicates\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">var<\/span> uniqueHrefValues = allHrefValues.filter(<span style=\"color:#00a\">function<\/span>(href, index) { <span style=\"color:#00a\">return<\/span> allHrefValues.indexOf(href) === index; });\n<\/code><\/pre>\n<\/div>\n<p>As you can see, in order to run the <code>map()<\/code> method against the list returned by <code>document.querySelectorAll<\/code>, you need to invoke the method from the array prototype. It\u2019s a good thing to keep in mind if you ever find yourself working with <code>document.querySelectorAll<\/code>.<\/p>\n<h3 id=\"using-elementmatches\">Using <code>element.matches<\/code><\/h3>\n<p>If you want to check if any given element <strong>matches<\/strong> a specific CSS selector, you can use the <code>matches()<\/code> method like this:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#aaa;font-style:italic\">\/\/ Check if the clicked element is an outbound link\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">function<\/span> checkIfClickedElementIsOutbound() {\n  <span style=\"color:#00a\">var<\/span> element = {{Click Element}};\n  <span style=\"color:#00a\">if<\/span> (element.matches(<span style=\"color:#a50\">'a:not([href=\"mydomain.com\"])'<\/span>) {\n    <span style=\"color:#00a\">return<\/span> <span style=\"color:#00a\">true<\/span>;\n  } <span style=\"color:#00a\">else<\/span> {\n    <span style=\"color:#00a\">return<\/span> <span style=\"color:#00a\">false<\/span>;\n  }\n}\n<\/code><\/pre>\n<\/div>\n<p>You invoke the <code>matches()<\/code> method on the element itself (the element has to be an HTML element), and like <code>querySelector<\/code> \/ <code>querySelectorAll<\/code>, you pass the selector as a string argument. The method returns <code>true<\/code> for a match, and <code>false<\/code> otherwise.<\/p>\n<p>The thing about <code>matches()<\/code> is that it didn\u2019t use to have <a href=\"https:\/\/caniuse.com\/#feat=matchesselector\">stellar browser support<\/a>, so if you want to use these methods with Internet Explorer in mind, you might need to implement a <strong>polyfill<\/strong> to extend the support (see <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Element\/matches#Polyfill\">here<\/a> for inspiration).<\/p>\n<p>Luckily, the <code>matches()<\/code> method is abstracted in Google Tag Manager when using triggers, which is by far the most common use case. So let\u2019s dive right in!<\/p>\n<h2 id=\"css-selectors-in-google-tag-manager\">CSS selectors in Google Tag Manager<\/h2>\n<p>In <strong>Google Tag Manager<\/strong>, you\u2019ll find CSS selectors in a number of places.<\/p>\n<p>You can use them as the selection method in the DOM Element variable:<\/p>\n<div style=\"aspect-ratio: 1326 \/ 844;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/dom-element-css.jpg\" title=\"DOM element and CSS\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"844\" width=\"1326\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/dom-element-css.jpg#ZgotmplZ\" alt=\"DOM element and CSS\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Using a CSS selector here lets you target specific elements that might not have the ID attribute (the only other selection method provided).<\/p>\n<p>You can also find the same option in the <a href=\"https:\/\/www.simoahava.com\/analytics\/element-visibility-trigger-google-tag-manager\/\">Element Visibility<\/a> trigger:<\/p>\n<div style=\"aspect-ratio: 1794 \/ 974;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-visibility-css.jpg\" title=\"Element visibility and CSS\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"974\" width=\"1794\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-visibility-css.jpg#ZgotmplZ\" alt=\"Element visibility and CSS\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Whereas the DOM Element variable only returns the <strong>first<\/strong> matching element (thus being similar to <code>document.querySelector<\/code>), the Element Visibility trigger can be set to target <strong>all<\/strong> the matching elements, making CSS selectors super powerful in this particular trigger type.<\/p>\n<p>The third, and by far the most useful scenario for CSS selectors in Google Tag Manager is the <a href=\"https:\/\/www.simoahava.com\/analytics\/matches-css-selector-operator-in-gtm-triggers\/\">matches CSS selector predicate<\/a> when used together with the <strong>{{Click Element}}<\/strong> built-in variable.<\/p>\n<h3 id=\"the-click-element-variable\">The Click Element variable<\/h3>\n<p>The <strong>Click Element<\/strong> variable is a <a href=\"https:\/\/www.simoahava.com\/analytics\/variable-guide-google-tag-manager\/#built-in-variables\">Built-in variable<\/a> that you need to <strong>enable<\/strong> before you can use. The easiest way to enable it is to go to <strong>Variables<\/strong> via GTM\u2019s main navigation, and click the blue <strong>Configure<\/strong> button in the top corner of the content.<\/p>\n<div style=\"aspect-ratio: 2516 \/ 740;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/variables-configure.jpg\" title=\"Variables and configure in GTM\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"740\" width=\"2516\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/variables-configure.jpg#ZgotmplZ\" alt=\"Variables and configure in GTM\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>In the overlay that opens, check the box next to <strong>Click Element<\/strong> and you\u2019re done. Now you can choose the Click Element variable in all the variable drop-downs of GTM.<\/p>\n<p><strong>Click Element<\/strong> returns the <strong>HTML element<\/strong> that was the target of the auto-event trigger action. In other words:<\/p>\n<ul>\n<li>\n<p>It returns the <strong>clicked element<\/strong> when using the Click \/ All Elements and Click \/ Just Links triggers.<\/p>\n<\/li>\n<li>\n<p>It returns the <strong>submitted form element<\/strong> when using the Form Submission trigger.<\/p>\n<\/li>\n<li>\n<p>It returns the <a href=\"https:\/\/www.simoahava.com\/analytics\/use-click-variables-with-element-visibility-trigger\/\"><strong>matched element that became visible<\/strong><\/a> when using the Element Visibility trigger.<\/p>\n<\/li>\n<\/ul>\n<p>Because it returns an HTML element, you can use it in your Custom HTML tags and Custom JavaScript variables together with typical HTML element methods such as <code>getAttribute<\/code>, <code>appendChild<\/code>, and yes, <code>matches<\/code>.<\/p>\n<p>In GTM, you\u2019ll use it most often, I\u2019m confident enough to say, with the <strong>matches CSS selector<\/strong> predicate in your Click and Form triggers. It\u2019s not that useful with the Element Visibility trigger, since you already specify the set of matching elements with the CSS selector setting in the trigger.<\/p>\n<h3 id=\"the-matches-css-selector-predicate\">The Matches CSS Selector predicate<\/h3>\n<p>You can use the <strong>matches CSS selector<\/strong> trigger predicate together with the <strong>Click Element<\/strong> variable to check if the element matches a specific selector (d\u2019oh).<\/p>\n<p>This is particularly useful with the <strong>All Elements<\/strong> trigger, since it truly fires when <strong>anything<\/strong> on the page is clicked, and you can use CSS selectors to delimit the tag to which the trigger is attached from firing all too often.<\/p>\n<p>To make it work, you need to first check the <strong>This trigger fires on\u2026Some Clicks\/Some Link Clicks\/Some Forms<\/strong> option, then select the <strong>Click Element<\/strong> variable from the variable selector, the <strong>matches CSS selector<\/strong> predicate from the predicate selector, and then type the selector in the field to the right, like so:<\/p>\n<div style=\"aspect-ratio: 1794 \/ 722;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/trigger-matches-css.jpg\" title=\"Trigger matches CSS\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"722\" width=\"1794\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/trigger-matches-css.jpg#ZgotmplZ\" alt=\"Trigger matches CSS\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>One thing to keep in mind is that the <strong>All Elements<\/strong> truly captures the <strong>exact<\/strong> element the user clicked. Thus it might be something nested within the element you actually drafted the selector for. With the All Elements trigger, you should make liberal use of the wildcard (<code>*<\/code>) selector. Read <a href=\"https:\/\/www.simoahava.com\/analytics\/use-wildcard-css-selectors-with-all-elements-triggers\/\">this article<\/a> for more information.<\/p>\n<p>In the reference chapter below, I have included what a Click trigger would look like for all the selectors listed in the reference.<\/p>\n<h2 id=\"css-selector-reference-for-google-tag-manager\">CSS selector reference for Google Tag Manager<\/h2>\n<p>The reference below is a modified (slimmed down) version of the <a href=\"https:\/\/www.w3schools.com\/cssref\/css_selectors.asp\">w3schools\u2019 excellent resource<\/a>. I\u2019ve tailored the different selectors with imaginary Google Tag Manager use cases in mind.<\/p>\n<p>Remember that you can combine selectors to identify different aspects of the element. When combining selectors, put them one after the other with <strong>no<\/strong> whitespace in between. For example, to target all <code><a\/><\/code> elements that have the <code>author<\/code> class, <code>simo<\/code> as the ID, and that are also outbound links, use something like this:<\/p>\n<p><code>a.author#simo:not([href=\"mydomain.com\"])<\/code><\/p>\n<p>The order is inconsequential, but it\u2019s customary to add <strong>pseudo-classes<\/strong> (e.g. <code>:checked<\/code>, <code>:not<\/code>) to the end for readability.<\/p>\n<h3 id=\"class\">.class<\/h3>\n<p>Matches elements that have the given class as one of the class names in their <code>class<\/code> attribute.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">a <span style=\"color:#1e90ff\">class<\/span>=<span style=\"color:#a50\">\"highlight author\"<\/span> <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/author-page\/\"<\/span>&gt;\n  span&gt;Simo Ahava<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1780 \/ 700;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/class-just-links.jpg\" title=\"Class - just links\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"700\" width=\"1780\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/class-just-links.jpg#ZgotmplZ\" alt=\"Class - just links\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>.author<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the link is clicked. Clicks on the <code><span\/><\/code> work too, since the Just Links trigger automatically retrieves the closes wrapping <code><a\/><\/code> element of whatever was actually clicked.<\/p>\n<h3 id=\"id\">#id<\/h3>\n<p>Matches elements that have the given ID as the value of their <code>id<\/code> attribute.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">class<\/span>=<span style=\"color:#a50\">\"date\"<\/span>&gt;\n  a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/archives\"<\/span>&gt;\n    span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"date\"<\/span>&gt;2019-04-09<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1778 \/ 564;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/id-all-elements.jpg\" title=\"ID - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"564\" width=\"1778\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/id-all-elements.jpg#ZgotmplZ\" alt=\"ID - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>#date<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the <code><span id=\"&quot;date&quot;\">...<\/span><\/code> element is clicked.<\/p>\n<h3 id=\"element\">element<\/h3>\n<p>Matches elements that are the given <code>element<\/code> (e.g. <code>a<\/code> for links, <code>img<\/code> for images).<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">a <span style=\"color:#1e90ff\">class<\/span>=<span style=\"color:#a50\">\"author\"<\/span> <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/author-page\"<\/span>&gt;\n  img <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"simo\"<\/span> <span style=\"color:#1e90ff\">src<\/span>=<span style=\"color:#a50\">\"simo.jpg\"<\/span>\/&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>img#simo<\/code><\/p>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1776 \/ 570;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-all-elements.jpg\" title=\"Element - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"570\" width=\"1776\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-all-elements.jpg#ZgotmplZ\" alt=\"Element - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the clicked element is the <code><img id=\"&quot;simo&quot;...\/\"\/><\/code>. As you can see, the selector combines both <code>element<\/code> and <code>id<\/code>, meaning the matched element must be both an image and have the ID <code>simo<\/code>.<\/p>\n<h3 id=\"elementelement\">element,element<\/h3>\n<p>Matches elements that can be selected with <strong>ANY<\/strong> of the selectors separated by a comma (you can add multiple selectors, each separated by a comma).<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">a <span style=\"color:#1e90ff\">class<\/span>=<span style=\"color:#a50\">\"author\"<\/span> <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/author-page\"<\/span>&gt;\n  img <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"simo_img\"<\/span> <span style=\"color:#1e90ff\">src<\/span>=<span style=\"color:#a50\">\"simo.jpg\"<\/span>\/&gt;\n  p <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"simo_name\"<\/span>&gt;Name: Simo Ahava<span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1776 \/ 558;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/multiple-selectors-all-elements.jpg\" title=\"Multiple selectors - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"558\" width=\"1776\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/multiple-selectors-all-elements.jpg#ZgotmplZ\" alt=\"Multiple selectors - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>img#simo_img, p#simo_name<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on EITHER <code><img id=\"&quot;simo_img&quot;...\/\"\/><\/code> OR <code><\/p>\n<p id=\"&quot;simo_name&quot;\">...<\/p>\n<p><\/code>.<\/p>\n<h3 id=\"element-element\">element element<\/h3>\n<p>Matches the rightmost element when it is within the leftmost element in the DOM tree. The relationship does <strong>not<\/strong> have to be parent-child &#8211; it\u2019s enough that the left element wraps the right element at some point.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">section <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main\"<\/span>&gt;\n  div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"article\"<\/span>&gt;\n    a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/archives\"<\/span>&gt;\n      h1&gt;Hello world!<span style=\"color:#1e90ff;font-weight:bold\">h1<\/span>&gt;\n    <span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">section<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1800 \/ 582;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/wrap-element-all-elements.jpg\" title=\"Wrapping selectors - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"582\" width=\"1800\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/wrap-element-all-elements.jpg#ZgotmplZ\" alt=\"Wrapping selectors - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>section#main h1<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on <code\/> because one of its wrapping elements matches the first selector (<code>section#main<\/code>).<\/p>\n<h3 id=\"-wildcard\">* (wildcard)<\/h3>\n<p>Matches any element. Extremely useful when used with the Click \/ All Elements trigger.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"navi\"<\/span>&gt;\n  ul&gt;\n    li&gt;a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/home\"<\/span>&gt;Home<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n    li&gt;a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/products\"<\/span>&gt;Products<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n    li&gt;a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/contact\"<\/span>&gt;Contact us<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">ul<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1788 \/ 572;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/wildcard-all-elements.jpg\" title=\"Wildcard - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"572\" width=\"1788\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/wildcard-all-elements.jpg#ZgotmplZ\" alt=\"Wildcard - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div#navi, div#navi *<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires when the <code><\/p>\n<div id=\"&quot;navi&quot;\"> element or <strong>any<\/strong> of its nested elements (<code\/>, <code><\/p>\n<li\/><\/code> and <code><a\/><\/code>) are clicked.\n<p>The selector is <code>div#navi, div#navi *<\/code>. Based on what you have learned above, this is actually <strong>two<\/strong> selectors, <code>div#navi<\/code> and <code>div#navi *<\/code>, and the trigger will fire if either is clicked.<\/p>\n<p>The first selector matches clicks directly on the <code><\/p>\n<div id=\"&quot;navi&quot;\"> element. The second selector matches clicks on <strong>any<\/strong> element that is wrapped by <code><\/p>\n<div id=\"&quot;navi&quot;\">. The whitespace is important here. If the second selector were <code>div#navi &gt; *<\/code>, it would only match clicks on the <code\/>, as it\u2019s the only direct child of <code><\/p>\n<div id=\"&quot;navi&quot;\">.<\/p>\n<h3 id=\"elementelement-1\">element&gt;element<\/h3>\n<p>Matches the rightmost element when its direct parent is the element to the left.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">section <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main\"<\/span>&gt;\n  div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"article\"<\/span>&gt;\n    a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/archives\"<\/span>&gt;\n      h2&gt;Hello world!<span style=\"color:#1e90ff;font-weight:bold\">h2<\/span>&gt;\n    <span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">section<\/span>&gt;\nsection <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"end\"<\/span>&gt;\n  div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"footer\"<\/span>&gt;\n    h2&gt;Goodbye world!<span style=\"color:#1e90ff;font-weight:bold\">h2<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">section<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1774 \/ 570;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/parent-selector-all-elements.jpg\" title=\"Parent selector - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"570\" width=\"1774\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/parent-selector-all-elements.jpg#ZgotmplZ\" alt=\"Parent selector - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div&gt;h2<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on <code><\/p>\n<h2>Goodbye world!<\/h2>\n<p><\/code> because its direct parent is <code><\/p>\n<div>. It will <strong>not<\/strong> fire on <code><\/p>\n<h2>Hello world!<\/h2>\n<p><\/code> because that element\u2019s direct parent is <code><a\/><\/code>.<\/p>\n<h3 id=\"elementelement-2\">element+element<\/h3>\n<p>Matches the rightmost element if it comes directly after the leftmost element. They must share the same parent.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author\"<\/span>&gt;\n  img <span style=\"color:#1e90ff\">src<\/span>=<span style=\"color:#a50\">\"\/author.jpg\"<\/span> <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author_image\"<\/span>\/&gt;\n  p&gt;Author name<span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1776 \/ 556;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-after-element-all-elements.jpg\" title=\"Element after element - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"556\" width=\"1776\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-after-element-all-elements.jpg#ZgotmplZ\" alt=\"Element after element - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>img#author_image+p<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on the <code\/>, because it is right after the <code><img id=\"&quot;author_image&quot;\/\"\/><\/code>.<\/p>\n<h3 id=\"element1element2\">element1~element2<\/h3>\n<p>Matches the rightmost element if it is preceded by the leftmost element. They must share the same parent. In other words, it\u2019s slightly less strict than the previous selector, in that the preceding element does not have to be immediately next to the targeted element.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author\"<\/span>&gt;\n  img <span style=\"color:#1e90ff\">src<\/span>=<span style=\"color:#a50\">\"\/author.jpg\"<\/span> <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author_image\"<\/span>\/&gt;\n  span&gt;Author name<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"https:\/\/www.simoahava.com\"<\/span>&gt;Author home page<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1780 \/ 554;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-preceded-all-elements.jpg\" title=\"Element preceded - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"554\" width=\"1780\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/element-preceded-all-elements.jpg#ZgotmplZ\" alt=\"Element preceded - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>img#author_image~a<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on the <code><a\/><\/code>, because it is preceded by <code><img id=\"&quot;author_image&quot;\/\"\/><\/code>.<\/p>\n<h3 id=\"attribute\">[attribute]<\/h3>\n<p>Matches if the element has the given attribute.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_content\"<\/span>&gt;\n  div <span style=\"color:#1e90ff\">data-name<\/span>=<span style=\"color:#a50\">\"gtm_example\"<\/span>&gt;\n    span&gt;GTM examples<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1776 \/ 546;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-all-elements.jpg\" title=\"Attribute - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"546\" width=\"1776\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-all-elements.jpg#ZgotmplZ\" alt=\"Attribute - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div[data-name]&gt;span<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on the <code><span\/><\/code>, because its direct parent is a <code><\/p>\n<div> with the <code>data-name<\/code> attribute.<\/p>\n<h3 id=\"attributevalue\">[attribute=value]<\/h3>\n<p>Matches if the element has the given attribute with the exact value.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_content\"<\/span>&gt;\n  div <span style=\"color:#1e90ff\">data-name<\/span>=<span style=\"color:#a50\">\"gtm_example\"<\/span>&gt;\n    span&gt;GTM example<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;\n  div <span style=\"color:#1e90ff\">data-name<\/span>=<span style=\"color:#a50\">\"second_gtm_example\"<\/span>&gt;\n    span&gt;Another GTM example<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1240 \/ 344;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-all-elements.jpg\" title=\"Attribute value - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"344\" width=\"1240\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-all-elements.jpg#ZgotmplZ\" alt=\"Attribute value - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div[data-name=\"second_gtm_example\"]&gt;span<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on the <strong>second<\/strong> <code><span\/><\/code>, because only it has a direct parent whose <code>data-name<\/code> attribute has the value <code>second_gtm_example<\/code>.<\/p>\n<h3 id=\"attributevalue-1\">[attribute^=value]<\/h3>\n<p>Matches if the element has the given attribute whose value starts with the provided string.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_content\"<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"product_12345\"<\/span>&gt;\n    Product 12345\n  <span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"product_23456\"<\/span>&gt;\n    Product 23456\n  <span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"attachment_12345\"<\/span>&gt;\n    Attachment 12345\n  <span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1768 \/ 564;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-starts-all-elements.jpg\" title=\"Attribute value starts - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"564\" width=\"1768\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-starts-all-elements.jpg#ZgotmplZ\" alt=\"Attribute value starts - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>span[id^=\"product\"]<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on either of the two <code><span\/><\/code> elements whose ID starts with <code>product<\/code>. It will not fire if the click lands on the third span, because that element ID starts with <code>attachment<\/code>.<\/p>\n<h3 id=\"attributevalue-2\">[attribute$=value]<\/h3>\n<p>Matches if the element has the given attribute whose value ends with the provided string.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_content\"<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"product_12345\"<\/span>&gt;\n    Product 12345\n  <span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"product_23456\"<\/span>&gt;\n    Product 23456\n  <span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"attachment_12345\"<\/span>&gt;\n    Attachment 12345\n  <span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1788 \/ 556;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-ends-all-elements.jpg\" title=\"Attribute value ends - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"556\" width=\"1788\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-ends-all-elements.jpg#ZgotmplZ\" alt=\"Attribute value ends - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>span[id$=\"_12345\"]<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on either the first <code><span\/><\/code> or the last <code><span\/><\/code>, since both elements\u2019 ID attributes end with <code>_12345<\/code>. It will not fire if the click lands on <code><span id=\"&quot;product_23456&quot;\"\/><\/code>, since that ID does not end with <code>_12345<\/code>.<\/p>\n<h3 id=\"attributevalue-3\">[attribute*=value]<\/h3>\n<p>Matches if the element has the given attribute whose value contains the provided string.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author\"<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"simo_ahava_profile\"<\/span>&gt;Simo's profile<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"profile_benjamin_ahava\"<\/span>&gt;Benjamin's profile<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n  span <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"derek_anderson\"<\/span>&gt;Derek's profile<span style=\"color:#1e90ff;font-weight:bold\">span<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1760 \/ 562;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-contains-all-elements.jpg\" title=\"Attribute value contains - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"562\" width=\"1760\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/attribute-value-contains-all-elements.jpg#ZgotmplZ\" alt=\"Attribute value contains - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div#author &gt; span[id*=\"ahava\"]<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on either of the first two <code><span\/><\/code> elements, since they have IDs that <strong>contain<\/strong> the string <code>ahava<\/code>. It will not fire for the third <code><span\/><\/code> because that element\u2019s ID attribute does not contain the string <code>ahava<\/code>.<\/p>\n<h3 id=\"checked\">:checked<\/h3>\n<p>Matches if the given element is <strong>checked<\/strong> (radio buttons, checkboxes, and <code><option\/><\/code> elements within select menus).<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">form <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"contact-us\"<\/span>&gt;\n  My name: input <span style=\"color:#1e90ff\">type<\/span>=<span style=\"color:#a50\">\"text\"<\/span> <span style=\"color:#1e90ff\">name<\/span>=<span style=\"color:#a50\">\"name\"<\/span> \/&gt;br \/&gt;\n  I consent to everything input <span style=\"color:#1e90ff\">type<\/span>=<span style=\"color:#a50\">\"checkbox\"<\/span> <span style=\"color:#1e90ff\">name<\/span>=<span style=\"color:#a50\">\"consent\"<\/span> \/&gt;br \/&gt;\n  input <span style=\"color:#1e90ff\">type<\/span>=<span style=\"color:#a50\">\"submit\"<\/span> \/&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">form<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1774 \/ 548;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/checked-all-elements.jpg\" title=\"Checked - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"548\" width=\"1774\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/checked-all-elements.jpg#ZgotmplZ\" alt=\"Checked - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>input[name=\"consent\"]:checked<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on the checkbox <strong>when it is checked<\/strong> (i.e. the user <strong>unchecks<\/strong> it).<\/p>\n<h3 id=\"first-child\">:first-child<\/h3>\n<p>Matches if the given element is the first child of its parent.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">ul <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_navigation\"<\/span>&gt;\n  li&gt;Home<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  li&gt;a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/products\"<\/span>&gt;Products<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  li&gt;a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/contact\"<\/span>&gt;Contact<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">ul<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1780 \/ 554;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/first-child-all-elements.jpg\" title=\"First child - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"554\" width=\"1780\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/first-child-all-elements.jpg#ZgotmplZ\" alt=\"First child - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>ul#main_navigation &gt; li:first-child<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on <code><\/p>\n<li>Home<\/li>\n<p><\/code> since it is the first child element of its direct parent.<\/p>\n<h3 id=\"first-of-type\">:first-of-type<\/h3>\n<p>Matches if the given element is the first element of its type (e.g. <code>p<\/code>, <code>img<\/code>, <code>span<\/code>) of its parent.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author_info\"<\/span>&gt;\n  a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/author\"<\/span>&gt;Simo Ahava<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n  p&gt;Web Analytics Developer<span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n  p&gt;Ukulele and death metal enthusiast<span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1786 \/ 548;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/first-of-type-all-elements.jpg\" title=\"First of type - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"548\" width=\"1786\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/first-of-type-all-elements.jpg#ZgotmplZ\" alt=\"First of type - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div#author_info &gt; p:first-of-type<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on the <code><\/p>\n<p>Web Analytics Developer<\/p>\n<p><\/code> since it is the first <code\/> under its parent.<\/p>\n<h3 id=\"last-child\">:last-child<\/h3>\n<p>Matches if the given element is the last child element of its parent (the reverse of <code>:first-child<\/code>).<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">ul <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_navigation\"<\/span>&gt;\n  li&gt;GTM<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  li&gt;Ukulele<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  li&gt;Death metal<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">ul<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1804 \/ 550;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/last-child-all-elements.jpg\" title=\"Last child - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"550\" width=\"1804\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/last-child-all-elements.jpg#ZgotmplZ\" alt=\"Last child - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>ul#main_navigation &gt; li:last-child<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on <code><\/p>\n<li>Death metal<\/li>\n<p><\/code> since it is the last child element of its parent.<\/p>\n<h3 id=\"last-of-type\">:last-of-type<\/h3>\n<p>Matches if the given element is the last element of its type of its parent.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author_info\"<\/span>&gt;\n  a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"\/author\"<\/span>&gt;Simo Ahava<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n  p&gt;Web Analytics Developer<span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n  p&gt;Ukulele and death metal enthusiast<span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1780 \/ 560;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/last-of-type-all-elements.jpg\" title=\"Last of type - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"560\" width=\"1780\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/last-of-type-all-elements.jpg#ZgotmplZ\" alt=\"Last of type - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>div#author_info p:last-of-type<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on <code><\/p>\n<p>Ukulele and death metal enthusiast<\/p>\n<p><\/code> since it is the last <code\/> under its parent.<\/p>\n<h3 id=\"notselector\">:not(selector)<\/h3>\n<p>Matches if the given element does <strong>not<\/strong> match the selector within the parentheses.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">div <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"author\"<\/span>&gt;\n  p&gt;\n    a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"https:\/\/www.simoahava.com\/\"<\/span>&gt;Home page<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n  p&gt;\n    a <span style=\"color:#1e90ff\">href<\/span>=<span style=\"color:#a50\">\"https:\/\/tagmanager.google.com\/\"<\/span>&gt;Favorite hobby<span style=\"color:#1e90ff;font-weight:bold\">a<\/span>&gt;\n  <span style=\"color:#1e90ff;font-weight:bold\">p<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">div<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1792 \/ 684;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/not-just-links.jpg\" title=\"Not - just links\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"684\" width=\"1792\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/not-just-links.jpg#ZgotmplZ\" alt=\"Not - just links\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>a:not([href*=\"simoahava.com])<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires when the click lands on the second link (<code><a href=\"&quot;https:\/\/tagmanager.google.com\/&quot;\">Favorite hobby<\/a><\/code>). This is because the CSS selector targets all link elements (<code><a\/><\/code>) that do <strong>not<\/strong> match the CSS selector <code>[href*=\"simoahava.com\"]<\/code>. In other words the link must <strong>not<\/strong> have a <code>href<\/code> attribute containing the string <code>simoahava.com<\/code>.<\/p>\n<h3 id=\"nth-childn\">:nth-child(n)<\/h3>\n<p>Matches if the given element is the nth child of its parent, where <code>n<\/code> is the number passed in the parentheses.<\/p>\n<p><strong>Sample HTML structure<\/strong><\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">ul <span style=\"color:#1e90ff\">id<\/span>=<span style=\"color:#a50\">\"main_navigation\"<\/span>&gt;\n  li&gt;GTM<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  li&gt;Ukulele<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n  li&gt;Death metal<span style=\"color:#1e90ff;font-weight:bold\">li<\/span>&gt;\n<span style=\"color:#1e90ff;font-weight:bold\">ul<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p><strong>Sample trigger<\/strong><\/p>\n<div style=\"aspect-ratio: 1780 \/ 552;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/04\/nth-child-all-elements.jpg\" title=\"Nth child - all elements\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"552\" width=\"1780\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/04\/nth-child-all-elements.jpg#ZgotmplZ\" alt=\"Nth child - all elements\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>Selector<\/strong><\/p>\n<p><code>ul#main_navigation &gt; li:nth-child(2)<\/code><\/p>\n<p><strong>Outcome<\/strong><\/p>\n<p>The trigger fires if the click lands on <code><\/p>\n<li>Ukulele<\/li>\n<p><\/code> since it is the <strong>second<\/strong> child (<code>nth-child(2)<\/code>) of its parent.<\/p>\n<h2 id=\"summary\">Summary<\/h2>\n<p>I\u2019ve said it many times, but I seriously think CSS selectors are high up there with JavaScript and regular expressions in the list of things you must learn if you want to master Google Tag Manager.<\/p>\n<p>Much of browser-based web analytics, especially when tracking interactions, is rooted in the ability to track interactions with specific elements. Often, we\u2019re recommended to use the <code>id<\/code> and <code>class<\/code> attributes these elements have, but it\u2019s very common that they don\u2019t actually have these attributes.<\/p>\n<p>It\u2019s in these situations that CSS selectors shine. They allow you to pinpoint every single and any element on any given page, since every element <strong>always<\/strong> has a unique position that can be targeted with some selector.<\/p>\n<p>Just remember my tip from earlier - always strive for a selector that is a simple as possible without compromising its ability to target the specific elements you want it to.<\/p>\n<\/p><\/div>\n<p>          <\/code><\/p>\n<\/div>\n<footer id=\"footer\" class=\"main-content-wrap\">\n  <span class=\"copyrights\"><br \/>\n    \u00a9 2025 Simo Ahava. All Rights Reserved<br \/>\n  <\/span><br \/>\n<\/footer>\n<p>      <\/code><\/p>\n<\/div>\n<p>    <\/code><\/div>\n<div id=\"about\">\n<div id=\"about-card\">\n<p>      <img decoding=\"async\" id=\"about-card-picture\" src=\"https:\/\/www.simoahava.com\/images\/simo.png\" alt=\"Author's picture\"\/><\/p>\n<h4 id=\"about-card-name\">Simo Ahava<\/h4>\n<p>Husband | Father | Analytics developer<br \/>simo (at) simoahava.com<\/p>\n<p>\n        <i class=\"fa fa-briefcase\"\/><br \/>\n        <br \/>Senior Data Advocate at Reaktor\n      <\/p>\n<p>\n        <i class=\"fa fa-map-marker\"\/><br \/>\n        <br \/>Finland\n      <\/p>\n<\/p><\/div>\n<\/div>\n<p>  <\/code><\/div>\n<p><\/code><\/p>\n<\/div>\n<p><\/code><\/p>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>. Since it has the id attribute, it\u2019s a reasonable expectation that it\u2019s the only such element on the page, thus even that short selector is very powerful. On the other hand, sometimes all you can do is use a really long, complex chain, because there are so few uniquely identifying features in the element [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":99846,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[38655,1531,2059,14495,46572,1791],"dealstore":[],"offerexpiration":[],"class_list":["post-99845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-css","tag-google","tag-guide","tag-manager","tag-selector","tag-tag"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CSS Selector Guide For Google Tag Manager - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=99845\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS Selector Guide For Google Tag Manager - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\". Since it has the id attribute, it\u2019s a reasonable expectation that it\u2019s the only such element on the page, thus even that short selector is very powerful. On the other hand, sometimes all you can do is use a really long, complex chain, because there are so few uniquely identifying features in the element [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=99845\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-20T17:30:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1784\" \/>\n\t<meta property=\"og:image:height\" content=\"570\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=99845#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=99845\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"CSS Selector Guide For Google Tag Manager\",\"datePublished\":\"2025-02-20T17:30:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=99845\"},\"wordCount\":2567,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=99845#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg\",\"keywords\":[\"CSS\",\"Google\",\"Guide\",\"Manager\",\"Selector\",\"TAG\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=99845#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=99845\",\"url\":\"https:\/\/fivemor.com\/?p=99845\",\"name\":\"CSS Selector Guide For Google Tag Manager - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=99845#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=99845#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg\",\"datePublished\":\"2025-02-20T17:30:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=99845#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=99845\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=99845#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg\",\"width\":1784,\"height\":570},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=99845#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Selector Guide For Google Tag Manager\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS Selector Guide For Google Tag Manager - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=99845","og_locale":"en_US","og_type":"article","og_title":"CSS Selector Guide For Google Tag Manager - Som2ny Network","og_description":". Since it has the id attribute, it\u2019s a reasonable expectation that it\u2019s the only such element on the page, thus even that short selector is very powerful. On the other hand, sometimes all you can do is use a really long, complex chain, because there are so few uniquely identifying features in the element [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=99845","og_site_name":"Som2ny Network","article_published_time":"2025-02-20T17:30:55+00:00","og_image":[{"width":1784,"height":570,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=99845#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=99845"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"CSS Selector Guide For Google Tag Manager","datePublished":"2025-02-20T17:30:55+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=99845"},"wordCount":2567,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=99845#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg","keywords":["CSS","Google","Guide","Manager","Selector","TAG"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=99845#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=99845","url":"https:\/\/fivemor.com\/?p=99845","name":"CSS Selector Guide For Google Tag Manager - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=99845#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=99845#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg","datePublished":"2025-02-20T17:30:55+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=99845#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=99845"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=99845#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/css-selector-google-tag-manager.jpg","width":1784,"height":570},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=99845#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"CSS Selector Guide For Google Tag Manager"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/99845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99845"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/99845\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/99846"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99845"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=99845"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=99845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}