{"id":627,"date":"2021-10-04T19:32:56","date_gmt":"2021-10-04T18:32:56","guid":{"rendered":"https:\/\/organicdigital.co\/blog\/?p=627"},"modified":"2026-09-21T12:07:28","modified_gmt":"2026-09-21T11:07:28","slug":"how-to-easily-configure-multiple-urls-parameters-in-one-trigger-using-google-tag-manager","status":"publish","type":"post","link":"https:\/\/daveashworth.co\/blog\/how-to-easily-configure-multiple-urls-parameters-in-one-trigger-using-google-tag-manager\/","title":{"rendered":"How To: Create a GTM Trigger for Multiple URLs and Parameters"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>TL;DR:<\/strong> <br>If you need a Google Tag Manager trigger to match multiple URLs or query parameters, you don\u2019t need to create a separate condition for every variation. For smaller sets of patterns, you can use a regular expression within a single trigger. For longer or frequently changing lists, I prefer a Custom JavaScript variable that checks the current URL against an array of patterns and returns <code>true<\/code> when it finds a match.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_90 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/daveashworth.co\/blog\/how-to-easily-configure-multiple-urls-parameters-in-one-trigger-using-google-tag-manager\/#Why_I_needed_one_GTM_trigger_for_multiple_URL_patterns\" >Why I needed one GTM trigger for multiple URL patterns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/daveashworth.co\/blog\/how-to-easily-configure-multiple-urls-parameters-in-one-trigger-using-google-tag-manager\/#Match_multiple_URLs_in_GTM_using_regex\" >Match multiple URLs in GTM using regex<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/daveashworth.co\/blog\/how-to-easily-configure-multiple-urls-parameters-in-one-trigger-using-google-tag-manager\/#Match_multiple_URL_parameters_with_a_Custom_JavaScript_variable\" >Match multiple URL parameters with a Custom JavaScript variable<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_I_needed_one_GTM_trigger_for_multiple_URL_patterns\"><\/span>Why I needed one GTM trigger for multiple URL patterns<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you need a Google Tag Manager trigger to fire across <strong>multiple URL patterns or query parameters<\/strong>, but creating a separate trigger condition for every possible variation quickly becomes difficult to manage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I originally ran into this while dealing with unwanted parameterised and system-generated URLs on ecommerce websites. I wanted a single GTM trigger that could identify multiple URL patterns and then fire another tag when any of those patterns were present.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, you might want one trigger to match URLs containing any of the following:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>?limit=<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>?order=<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>?mode=<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\/catalog\/<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\/customer\/<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rather than creating a separate trigger for every pattern, you can handle them within <strong>one GTM trigger<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are two approaches I&#8217;ll show here: a simple regular expression for smaller sets of URL patterns, and a Custom JavaScript variable for longer lists that you want to maintain more easily.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I originally used this technique alongside a GTM-generated noindex tag. I&#8217;ve covered that implementation separately in my guide to <a href=\"https:\/\/daveashworth.co\/blog\/how-to-implement-robots-noindex-tag-with-google-tag-manager\/\">adding a noindex tag with Google Tag Manager<\/a>. The technique on this page isn&#8217;t specific to noindex tags though. You can use the same principle whenever a GTM trigger needs to match one of several URL patterns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Match_multiple_URLs_in_GTM_using_regex\"><\/span>Match multiple URLs in GTM using regex<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ll be honest, I hate Regex.&nbsp; I\u2019ve been in the coding game to varying degrees for over 20 years and bar the pipe symbol, aka OR which looks like |, I can never get them to work.&nbsp;&nbsp; So, if I can avoid them, I will.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But the pipe symbol is one option here, to a degree, so far as my limited knowledge goes anyway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want a GTM trigger to match several URL structures, a simple regular expression can be enough.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"882\" height=\"86\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-29-55.jpg\" alt=\"regex\n\" class=\"wp-image-629\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-29-55.jpg 882w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-29-55-300x29.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-29-55-150x15.jpg 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-29-55-768x75.jpg 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So, on my site, that would fire on:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/daveashworth.co\/services-and-consultancy\/\">https:\/\/daveashworth.co\/services-and-consultancy\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/daveashworth.co\/services-and-consultancy\/website-migrations-consultant\/\">https:\/\/daveashworth.co\/services-and-consultancy\/website-migrations-consultant\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/daveashworth.co\/support\/in-house\/\">https:\/\/daveashworth.co\/support\/in-house\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/daveashworth.co\/about\/testimonials\/\">https:\/\/daveashworth.co\/about\/testimonials\/<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Where it starts to get messy, is when you want to fire URL parameters via the = symbol (it might be easy, but as I say, I hate regex and am not willing to take this any further).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have a large number of URL patterns or parameters you need to match, managing them all in one input box gets a bit fiddly. The following solution therefore is FAR better:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Match_multiple_URL_parameters_with_a_Custom_JavaScript_variable\"><\/span>Match multiple URL parameters with a Custom JavaScript variable<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This a much more elegant approach, as you can use a bespoke JavaScript function to set up an array of URL structures and parameters to check for \u2013 if one of them is present in the current URL, the variable returns true, if not, it returns false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You would set up a Custom JavaScript Variable as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"771\" height=\"739\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-37-54.jpg\" alt=\"Custom JavaScript Variable\n\" class=\"wp-image-630\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-37-54.jpg 771w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-37-54-300x288.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-37-54-150x144.jpg 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-37-54-768x736.jpg 768w\" sizes=\"(max-width: 771px) 100vw, 771px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The full code is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function() \n{\n\tvar deIndexTheseURLs = \n\t&#91;\n\t\t'\/catalog\/',\n\t\t'\/catalogsearch\/',\n\t\t'\/customer\/',\n\t\t'cjdata=',\n\t\t'colour_shade=',\n\t\t'dir=',\n\t\t'extension_length=',\n\t\t'extension_style=',\n\t\t'extension_weight=',\n\t\t'gclid=',\n\t\t'hair_extension_colour=',\n\t\t'limit=',\n\t\t'mode=',\n\t\t'options=',\n\t\t'order=',\n\t\t'p=',\n\t\t'platform=',\n\t\t'product_list_order=',\n\t\t'store=',\n\t\t'wig_length=',\n\t\t'q='\n\t];\n\n\tfor (var i = 0; i &lt; deIndexTheseURLs.length; i += 1) \n\t{  \n\t\tif (document.location.href.indexOf(deIndexTheseURLs&#91;i]) &gt; -1) \n\t\t{\n\t\t\treturn true;\n\t\t}\n\t};\n\nreturn false;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, the list of structures is easy enough to manage and edit at any time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The array contains various structure formats, which is then looped through and checks against the current URL to see if the URL structure is a substring.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If it is, it returns true, if not false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You then set up a trigger to fire when the variable returns true, and associate this with your no index tag as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"766\" height=\"477\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-43-01.jpg\" alt=\"Custom Javascript Variable Trigger\" class=\"wp-image-631\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-43-01.jpg 766w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-43-01-300x187.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/10\/2021-10-04_17-43-01-150x93.jpg 150w\" sizes=\"(max-width: 766px) 100vw, 766px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And that\u2019s it. Easy.&nbsp; If you have any questions, queries or need any assistance getting this set up, feel free to get in touch, am always happy to help.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find out how to easily configure multiple URL structures and parameters via GTM with one easy to manage trigger<\/p>\n","protected":false},"author":1,"featured_media":632,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4],"tags":[],"class_list":["post-627","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tag-manager","category-crawl-rate"],"_links":{"self":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/comments?post=627"}],"version-history":[{"count":0,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/627\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media\/632"}],"wp:attachment":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media?parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/categories?post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/tags?post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}