{"id":10408,"date":"2024-11-06T22:34:38","date_gmt":"2024-11-06T22:34:38","guid":{"rendered":"https:\/\/ceowebltd.com\/blog\/?p=10408"},"modified":"2024-11-06T22:34:38","modified_gmt":"2024-11-06T22:34:38","slug":"how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2","status":"publish","type":"post","link":"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/","title":{"rendered":"How to use regex tables for advanced tag management in Google Tag Manager"},"content":{"rendered":"<p>Using regex tables for advanced tag management in <strong>Google Tag Manager<\/strong> (GTM) can significantly enhance your ability to control when and how tags are fired based on specific conditions. Regular expressions (regex) allow you to create more dynamic, flexible, and complex triggers and variables. Here\u2019s a detailed guide on how to use regex tables for advanced tag management in GTM.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 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-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#1_Understanding_Regex_and_Regex_Tables\" title=\"1. Understanding Regex and Regex Tables\">1. Understanding Regex and Regex Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#2_Use_Cases_for_Regex_Tables_in_GTM\" title=\"2. Use Cases for Regex Tables in GTM\">2. Use Cases for Regex Tables in GTM<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#3_Setting_Up_Regex_Tables_in_GTM\" title=\"3. Setting Up Regex Tables in GTM\">3. Setting Up Regex Tables in GTM<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#Step_1_Create_a_New_Variable\" title=\"Step 1: Create a New Variable\">Step 1: Create a New Variable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#Step_2_Add_a_Regex_Table\" title=\"Step 2: Add a Regex Table\">Step 2: Add a Regex Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#Step_3_Use_Regex_Table_for_Advanced_Matching\" title=\"Step 3: Use Regex Table for Advanced Matching\">Step 3: Use Regex Table for Advanced Matching<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#Step_4_Use_the_Regex_Table_in_Triggers\" title=\"Step 4: Use the Regex Table in Triggers\">Step 4: Use the Regex Table in Triggers<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#4_Advanced_Examples_of_Regex_Table_Use_in_GTM\" title=\"4. Advanced Examples of Regex Table Use in GTM\">4. Advanced Examples of Regex Table Use in GTM<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#Example_1_Firing_Tags_on_Product_and_Category_Pages\" title=\"Example 1: Firing Tags on Product and Category Pages\">Example 1: Firing Tags on Product and Category Pages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#Example_2_Tracking_Specific_UTM_Parameters\" title=\"Example 2: Tracking Specific UTM Parameters\">Example 2: Tracking Specific UTM Parameters<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#5_Testing_and_Debugging\" title=\"5. Testing and Debugging\">5. Testing and Debugging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#6_Conclusion\" title=\"6. Conclusion\">6. Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"1_Understanding_Regex_and_Regex_Tables\"><\/span><strong>1. Understanding Regex and Regex Tables<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Before diving into GTM, it\u2019s essential to understand what regex is and how it can be applied to tag management:<\/p>\n<ul>\n<li><strong>Regex (Regular Expressions)<\/strong> is a powerful tool for pattern matching within strings. It allows you to search for and match strings based on patterns rather than exact text.<\/li>\n<li><strong>Regex Tables in GTM<\/strong> allow you to create a rule-based structure where regex is applied to a set of conditions or URL patterns, making the tag firing logic much more robust.<\/li>\n<\/ul>\n<p>A <strong>Regex Table<\/strong> is typically used in GTM to create conditions based on URL, referrer, or other variables. This allows GTM to determine the appropriate action (e.g., firing a tag) based on how specific patterns or conditions are met.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Use_Cases_for_Regex_Tables_in_GTM\"><\/span><strong>2. Use Cases for Regex Tables in GTM<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can use regex tables for various purposes, such as:<\/p>\n<ul>\n<li><strong>Firing tags based on URL patterns<\/strong>: For instance, firing a tag only on product pages, checkout pages, or specific sections of a site.<\/li>\n<li><strong>Capturing dynamic parameters from URLs<\/strong>: You can extract URL parameters like &#8220;user_id&#8221; or &#8220;product_category&#8221; dynamically and use them in tags or triggers.<\/li>\n<li><strong>Excluding certain pages or actions<\/strong>: Preventing tags from firing on specific pages or under certain conditions.<\/li>\n<li><strong>Customizing triggers based on referrer<\/strong>: Firing tags only if a user comes from a specific referral URL.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"3_Setting_Up_Regex_Tables_in_GTM\"><\/span><strong>3. Setting Up Regex Tables in GTM<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Let\u2019s walk through a practical example of how to use regex tables in Google Tag Manager.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Step_1_Create_a_New_Variable\"><\/span><strong>Step 1: Create a New Variable<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li><strong>Go to your GTM container<\/strong> and click on <strong>Variables<\/strong> in the left-hand menu.<\/li>\n<li>Click <strong>New<\/strong> to create a new variable. This variable will store the value that will be evaluated against your regex table.<\/li>\n<li>Choose <strong>URL<\/strong> (or another appropriate built-in variable such as Referrer, Page Path, etc.).<\/li>\n<li>Select the <strong>Variable Type<\/strong> (e.g., &#8220;Page URL&#8221; or &#8220;Page Path&#8221;) based on what you want to track.<\/li>\n<li>Save the variable.<\/li>\n<\/ol>\n<h4><span class=\"ez-toc-section\" id=\"Step_2_Add_a_Regex_Table\"><\/span><strong>Step 2: Add a Regex Table<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li><strong>Create a New Trigger<\/strong> to fire tags based on the regex table.<\/li>\n<li>In the Trigger Configuration, select <strong>Page View<\/strong> (or whichever trigger type you require) as the trigger event.<\/li>\n<li>Click on the <strong>Choose Trigger Type<\/strong> dropdown and select <strong>Page URL<\/strong> (or another built-in variable if using something else like Referrer).<\/li>\n<li>In the condition section, instead of using the regular \u201cequals\u201d or \u201ccontains\u201d operators, select <strong>Matches Regex<\/strong>.<\/li>\n<\/ol>\n<h4><span class=\"ez-toc-section\" id=\"Step_3_Use_Regex_Table_for_Advanced_Matching\"><\/span><strong>Step 3: Use Regex Table for Advanced Matching<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li>Create a <strong>Custom JavaScript Variable<\/strong> for the Regex Table:\n<ul>\n<li>Go to <strong>Variables<\/strong> and click on <strong>New<\/strong>.<\/li>\n<li>Choose <strong>Custom JavaScript<\/strong> as the variable type.<\/li>\n<li>In the code editor, add the following example code:<\/li>\n<\/ul>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">javascript<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center select-none py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-javascript\"><span class=\"hljs-keyword\">function<\/span>() {<br \/>\n  <span class=\"hljs-keyword\">var<\/span> url = {{<span class=\"hljs-title class_\">Page<\/span> <span class=\"hljs-variable constant_\">URL<\/span>}};<br \/>\n  <span class=\"hljs-keyword\">var<\/span> regexTable = [<br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/^\\\/product\\\/(.*)$\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'ProductPage'<\/span> }, <span class=\"hljs-comment\">\/\/ Match product pages<\/span><br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/^\\\/checkout\\\/\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'CheckoutPage'<\/span> }, <span class=\"hljs-comment\">\/\/ Match checkout pages<\/span><br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/\\\/category\\\/([^\/]+)\\\/\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'CategoryPage'<\/span> } <span class=\"hljs-comment\">\/\/ Match category pages<\/span><br \/>\n  ];<br \/>\n  <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-keyword\">var<\/span> i = <span class=\"hljs-number\">0<\/span>; i &lt; regexTable.<span class=\"hljs-property\">length<\/span>; i++) {<br \/>\n    <span class=\"hljs-keyword\">if<\/span> (url.<span class=\"hljs-title function_\">match<\/span>(regexTable[i].<span class=\"hljs-property\">regex<\/span>)) {<br \/>\n      <span class=\"hljs-keyword\">return<\/span> regexTable[i].<span class=\"hljs-property\">value<\/span>;<br \/>\n    }<br \/>\n  }<br \/>\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'OtherPage'<\/span>;<br \/>\n}<br \/>\n<\/code><\/div>\n<\/div>\n<p>This code uses a <strong>regex table<\/strong> to match URLs to different categories like product pages, checkout pages, and category pages.<\/li>\n<li><strong>Test the Regex Table<\/strong>: Before using it in triggers, you can preview the variable in GTM to ensure it returns the correct value based on your URL structure.<\/li>\n<\/ol>\n<h4><span class=\"ez-toc-section\" id=\"Step_4_Use_the_Regex_Table_in_Triggers\"><\/span><strong>Step 4: Use the Regex Table in Triggers<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li><strong>Create a New Trigger<\/strong>:\n<ul>\n<li>Go to <strong>Triggers<\/strong> and click <strong>New<\/strong>.<\/li>\n<li>Select the <strong>Page View<\/strong> trigger type.<\/li>\n<li>Set up the trigger condition using your Custom JavaScript Variable. For example:\n<ul>\n<li><strong>Variable<\/strong>: The custom variable you created in Step 3.<\/li>\n<li><strong>Condition<\/strong>: &#8220;equals&#8221; or &#8220;contains&#8221; the value you&#8217;re looking for (e.g., \u201cProductPage\u201d or \u201cCheckoutPage\u201d).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Apply the Trigger to a Tag<\/strong>:\n<ul>\n<li>Once the trigger is created, go to the <strong>Tags<\/strong> section.<\/li>\n<li>Select the tag you want to fire.<\/li>\n<li>Under <strong>Triggering<\/strong>, select the newly created trigger based on your regex logic.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"4_Advanced_Examples_of_Regex_Table_Use_in_GTM\"><\/span><strong>4. Advanced Examples of Regex Table Use in GTM<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"Example_1_Firing_Tags_on_Product_and_Category_Pages\"><\/span><strong>Example 1: Firing Tags on Product and Category Pages<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Let\u2019s say you want to fire a specific tag only on pages that belong to a certain category or product. You can use a regex table to check the URL:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">javascript<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center select-none py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-javascript\"><span class=\"hljs-keyword\">function<\/span>() {<br \/>\n  <span class=\"hljs-keyword\">var<\/span> url = {{<span class=\"hljs-title class_\">Page<\/span> <span class=\"hljs-variable constant_\">URL<\/span>}};<br \/>\n  <span class=\"hljs-keyword\">var<\/span> regexTable = [<br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/^\\\/products\\\/(.*)$\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'ProductPage'<\/span> },  <span class=\"hljs-comment\">\/\/ Matches product pages<\/span><br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/^\\\/category\\\/([^\\\/]+)$\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'CategoryPage'<\/span> }  <span class=\"hljs-comment\">\/\/ Matches category pages<\/span><br \/>\n  ];<br \/>\n  <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-keyword\">var<\/span> i = <span class=\"hljs-number\">0<\/span>; i &lt; regexTable.<span class=\"hljs-property\">length<\/span>; i++) {<br \/>\n    <span class=\"hljs-keyword\">if<\/span> (url.<span class=\"hljs-title function_\">match<\/span>(regexTable[i].<span class=\"hljs-property\">regex<\/span>)) {<br \/>\n      <span class=\"hljs-keyword\">return<\/span> regexTable[i].<span class=\"hljs-property\">value<\/span>;<br \/>\n    }<br \/>\n  }<br \/>\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'OtherPage'<\/span>;<br \/>\n}<br \/>\n<\/code><\/div>\n<\/div>\n<p>This will allow you to fire tags only on product and category pages, enhancing the accuracy and relevance of your tag management.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Example_2_Tracking_Specific_UTM_Parameters\"><\/span><strong>Example 2: Tracking Specific UTM Parameters<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>If you want to fire a tag based on specific UTM parameters in the URL, you can create a regex table to match various UTM conditions:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">javascript<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><span class=\"\" data-state=\"closed\"><button class=\"flex gap-1 items-center select-none py-1\">Copy code<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-javascript\"><span class=\"hljs-keyword\">function<\/span>() {<br \/>\n  <span class=\"hljs-keyword\">var<\/span> url = {{<span class=\"hljs-title class_\">Page<\/span> <span class=\"hljs-variable constant_\">URL<\/span>}};<br \/>\n  <span class=\"hljs-keyword\">var<\/span> regexTable = [<br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/[?&amp;]utm_source=google\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'GoogleTraffic'<\/span> },<br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/[?&amp;]utm_medium=cpc\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'CPCTraffic'<\/span> },<br \/>\n    { <span class=\"hljs-attr\">regex<\/span>: <span class=\"hljs-regexp\">\/[?&amp;]utm_campaign=spring_sale\/<\/span>, <span class=\"hljs-attr\">value<\/span>: <span class=\"hljs-string\">'SpringSale'<\/span> }<br \/>\n  ];<br \/>\n  <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-keyword\">var<\/span> i = <span class=\"hljs-number\">0<\/span>; i &lt; regexTable.<span class=\"hljs-property\">length<\/span>; i++) {<br \/>\n    <span class=\"hljs-keyword\">if<\/span> (url.<span class=\"hljs-title function_\">match<\/span>(regexTable[i].<span class=\"hljs-property\">regex<\/span>)) {<br \/>\n      <span class=\"hljs-keyword\">return<\/span> regexTable[i].<span class=\"hljs-property\">value<\/span>;<br \/>\n    }<br \/>\n  }<br \/>\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'OtherTraffic'<\/span>;<br \/>\n}<br \/>\n<\/code><\/div>\n<\/div>\n<p>This will match different UTM parameters like <code>utm_source<\/code>, <code>utm_medium<\/code>, and <code>utm_campaign<\/code>, allowing you to fire specific tags based on the traffic source.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_Testing_and_Debugging\"><\/span><strong>5. Testing and Debugging<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Testing is crucial when using regex tables in GTM:<\/p>\n<ol>\n<li><strong>Use GTM\u2019s Preview Mode<\/strong>: Before publishing any changes, always preview the container in GTM\u2019s preview mode to see if your tags are firing correctly based on the regex conditions.<\/li>\n<li><strong>Use the GTM Debugger<\/strong>: You can use the <strong>Google Tag Manager Debug Console<\/strong> to inspect the variable values and see if the regex matches the expected patterns.<\/li>\n<li><strong>Test Regex Patterns<\/strong>: Tools like <strong>Regex101<\/strong> or <strong>RegExr<\/strong> allow you to test your regex patterns outside GTM to ensure they match the URLs correctly.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"6_Conclusion\"><\/span><strong>6. Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Using regex tables in Google Tag Manager is an excellent way to create dynamic and powerful tag management rules. By applying regex patterns to variables like URLs, referrers, and custom parameters, you can create highly targeted triggers that fire tags only under the right conditions. The flexibility of regex combined with GTM\u2019s user-friendly interface provides an effective solution for managing complex tag firing requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using regex tables for advanced tag management in Google Tag Manager (GTM) can significantly enhance your ability to control when and how tags are fired&#8230;<\/p>\n","protected":false},"author":214,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-10408","post","type-post","status-publish","format-standard","hentry","category-digital-marketing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use regex tables for advanced tag management in Google Tag Manager - CEOweb Ltd. Blog<\/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:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use regex tables for advanced tag management in Google Tag Manager - CEOweb Ltd. Blog\" \/>\n<meta property=\"og:description\" content=\"Using regex tables for advanced tag management in Google Tag Manager (GTM) can significantly enhance your ability to control when and how tags are fired...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/\" \/>\n<meta property=\"og:site_name\" content=\"CEOweb Ltd. Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-06T22:34:38+00:00\" \/>\n<meta name=\"author\" content=\"Emmanuel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Emmanuel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/\",\"url\":\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/\",\"name\":\"How to use regex tables for advanced tag management in Google Tag Manager - CEOweb Ltd. Blog\",\"isPartOf\":{\"@id\":\"https:\/\/ceowebltd.com\/blog\/#website\"},\"datePublished\":\"2024-11-06T22:34:38+00:00\",\"dateModified\":\"2024-11-06T22:34:38+00:00\",\"author\":{\"@id\":\"https:\/\/ceowebltd.com\/blog\/#\/schema\/person\/4759c204c0b0f1d134ec16e8ec777a6f\"},\"breadcrumb\":{\"@id\":\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ceowebltd.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use regex tables for advanced tag management in Google Tag Manager\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ceowebltd.com\/blog\/#website\",\"url\":\"https:\/\/ceowebltd.com\/blog\/\",\"name\":\"CEOweb Ltd. Blog\",\"description\":\"Guest Posting - Digital Marketing &amp; Web Services\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ceowebltd.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ceowebltd.com\/blog\/#\/schema\/person\/4759c204c0b0f1d134ec16e8ec777a6f\",\"name\":\"Emmanuel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ceowebltd.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9e883d40261b9b272de51992551b3eec4df631b7579a4fbec69c36a006dcbaf2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9e883d40261b9b272de51992551b3eec4df631b7579a4fbec69c36a006dcbaf2?s=96&d=mm&r=g\",\"caption\":\"Emmanuel\"},\"url\":\"https:\/\/ceowebltd.com\/blog\/author\/emmanuel\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use regex tables for advanced tag management in Google Tag Manager - CEOweb Ltd. Blog","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:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/","og_locale":"en_US","og_type":"article","og_title":"How to use regex tables for advanced tag management in Google Tag Manager - CEOweb Ltd. Blog","og_description":"Using regex tables for advanced tag management in Google Tag Manager (GTM) can significantly enhance your ability to control when and how tags are fired...","og_url":"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/","og_site_name":"CEOweb Ltd. Blog","article_published_time":"2024-11-06T22:34:38+00:00","author":"Emmanuel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Emmanuel","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/","url":"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/","name":"How to use regex tables for advanced tag management in Google Tag Manager - CEOweb Ltd. Blog","isPartOf":{"@id":"https:\/\/ceowebltd.com\/blog\/#website"},"datePublished":"2024-11-06T22:34:38+00:00","dateModified":"2024-11-06T22:34:38+00:00","author":{"@id":"https:\/\/ceowebltd.com\/blog\/#\/schema\/person\/4759c204c0b0f1d134ec16e8ec777a6f"},"breadcrumb":{"@id":"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ceowebltd.com\/blog\/how-to-use-regex-tables-for-advanced-tag-management-in-google-tag-manager-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ceowebltd.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to use regex tables for advanced tag management in Google Tag Manager"}]},{"@type":"WebSite","@id":"https:\/\/ceowebltd.com\/blog\/#website","url":"https:\/\/ceowebltd.com\/blog\/","name":"CEOweb Ltd. Blog","description":"Guest Posting - Digital Marketing &amp; Web Services","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ceowebltd.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ceowebltd.com\/blog\/#\/schema\/person\/4759c204c0b0f1d134ec16e8ec777a6f","name":"Emmanuel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ceowebltd.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9e883d40261b9b272de51992551b3eec4df631b7579a4fbec69c36a006dcbaf2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9e883d40261b9b272de51992551b3eec4df631b7579a4fbec69c36a006dcbaf2?s=96&d=mm&r=g","caption":"Emmanuel"},"url":"https:\/\/ceowebltd.com\/blog\/author\/emmanuel\/"}]}},"_links":{"self":[{"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/posts\/10408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/users\/214"}],"replies":[{"embeddable":true,"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/comments?post=10408"}],"version-history":[{"count":1,"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/posts\/10408\/revisions"}],"predecessor-version":[{"id":10409,"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/posts\/10408\/revisions\/10409"}],"wp:attachment":[{"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/media?parent=10408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/categories?post=10408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ceowebltd.com\/blog\/wp-json\/wp\/v2\/tags?post=10408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}