The Lookup Table variable has been available in GTM for a while now and is a really useful tool, but with one major limitation, it only uses exact match.... But not anymore!
Introducing the RegEx Table:
It works exactly the same as a look up table: takes in one variable and outputs something else, either a defined value or another variable.
But now instead of matching the input variable against an exact string, you can match it to a RegEx pattern.
Here's an example:
We want to fire an GA event on three pages of a site, but use a different event label for each page, depending on the page path.
Instead of making three tags, we can create one tag and use a lookup variable to set the event label each time.
Unfortunately we’re working with a non-perfect site and the three pages we’re tagging exist both with and without the ending /
As a result our lookup table looks like this:
Using the new RegEx table variable we can condense this:
The ? at the end means “0 or 1 of the previous character”, so with or without the final /
Now we’ve got 50% fewer rows!!!
This is just a simple example, and hasn’t saved that much time, but on a bigger scale there is a huge opportunity for more efficient tagging.
There are a couple of Advanced Settings in the variable to be aware of:
- Ignore Case – Exactly what is sounds like, choose between ignoring case of including it as something to match against. If this is ticked the string “Searchstar”, won’t match the RegEx “SearchStar”
- Full Matches Only – When this is ticked, your RegEx pattern must match the entire input. This is equivalent to having start (^) and end ($) anchors around your pattern.
- Enable Capture Groups & Replace – If this is ticked you can use dollar-sign replacement syntax to include part of your input in the output. More info in Simo’s blog linked below.
For more information on this new variable check out Simo Ahava’s blog here.
And for some help with RegEx, check out the following links: