Tag Management

GTM: Using Multiple Inputs for RegEx Tables

I’m a big fan of RegEx table variables in Google Tag Manager. These are especially useful if you have implemented a gtm blacklist with your GTM setup to avoid custom scripting. If that is your situation (likely not) then this variable type will provide some flexibility that you wouldn’t have otherwise.  Keep in mind, though, that RegEx Tables have one limiting factor that sometimes take a bit of extra work…they only allow for a single input variable:

This can be limiting in scenarios where you want to have an output that depends on a variety of inputs. As an example, let’s say that we want to deploy a bunch of Floodlights, each with a different activity string, based on a combination of an event category, event action and URL path. For this example, you can just assume that the event category and action are being pushed into the dataLayer. Now, I could probably create a trigger for each floodlight and avoid doing any of this; however I find that approach less scalable and tends to make a mess of your GTM configuration. Let’s just say I don’t want to be miserable so I decide to not create a trigger for each floodlight. Instead we can have all that logic in one place by just concatenating together the different variables we want and use the RegEx table to identify a match as needed. To do this I just create a new variable that pulls in all the other variables like so:

Notice that I like to use a name/value concatenation so it ends up looking like URL parameters. I use “^” as the delimiter since that is pretty unique. I avoid using delimiters that are leveraged in URLs (such as ?, &, #). Also using a name with the value helps to ensure that we don’t accidentally match on a value that is unexpectedly in one of the other variables.

With the concatenation of variables giving us a new, single input I can now set up my regex table as needed:

Once I have worked out my RegEx table logic to match correctly on what I want I then just plug it into my floodlight as normal:

And with that you have now deployed a bunch of floodlights with a single tag, trigger, and variable. I have found this to be useful in simplifying the GTM setup in a bunch of scenarios so I hope it helps you too!

 

 

Leave a Reply