This repository contains a Google Tag Manager Variable template similar to a RegEx Table, with the addition of being able to use multiple variables as input. This is an excellent resource about how to use a RegEx Table. You will be able to make use of the same functionality, with the addition ability of using multiple inputs.
- Open a Google Tag Manager web container and click into the Templates from the left sidebar menu.
- In the Variables Templates section, click on Search Gallery button.
- Click on the Search Icon then type "multiple inputs".
- Select the Multiple Inputs RegEx Table template to your workspace.
- Use the new template as needed.
Add as many inputs as you need. Individual input values will be concatenated using "_" (which can be changed in Advanced Settings) to get a final input string. You can enter Google Tag Manager variables such as {{ My Object }}.
The concatenation of the values in the Inputs Table will be matched against each Pattern in the RegEx Table, from top to bottom. When a match is found, the Output value from that row will be returned. Enter Patterns using Regular Expressions.
Explicitly set the value of this variable in case no match is made. Just like pattern outputs, this can be another Google Tag Manager variable.
The character that will be used to concatenate the input values, defaults to "_". For example, if there are two input values inside the Inputs Table, the first one being Foo
and the second one being Bar
, the final input will be Foo_Bar
.
If enabled, the patterns are matched regardless of case, and the returned value will be in lowercase. This option is checked by default.
If enabled, patterns must match entire input. This is equivalent to having start (^)
and end ($)
anchors implicitly around your pattern. If disabled, patterns will match when they are found anywhere in the input. Disabling this option may cause unexpected behavior with the "Capture Groups and Replace Functionality". This option is checked by default.
If enabled, you can use dollar-sign replacement syntax to include portions of the input (e.g. from capturing groups in the matched pattern) within the output. Given the limited support for regular expressions in Google Tag Manager templates, only $n
and $&
are supported. Additionally, only the first 5 capture groups are available.
Please note the following:
- Using this option with "Full Matches Only" disabled may result in unexpected behavior (i.e. returning the entire input value with the matched portion replaced).
- Using this option with "Ignore Case" enabled, the returned value from the group capture will be in lowercase.
This option is checked by default.
Let's assume the {{ DLV - Category }}
equals Form and the {{ DLV - Action }}
equals Submission.
The RegEx table will match the first pattern, giving an output of contact_form_submission
(all lowercase because of the Ignore Case option).
Let's assume the {{ DLV - Category }}
equals Banner and the {{ DLV - Action }}
equals Click.
The RegEx table will match the second pattern, giving an output of ad_click
.
Let's assume the {{ DLV - Category }}
equals WebVitals and the {{ DLV - Action }}
equals CLS.
The RegEx table will match the third pattern, giving an output of core_web_vitals_cls
.
Let's assume the {{ DLV - Category }}
equals User and the {{ DLV - Action }}
equals LogIn.
The RegEx table will match the fourth pattern, giving an output of authentication_log_in
.
See our contributing guidelines.