How to add multiple conditions in GTM (Google Tag Manager)?

Abhishek SharmaAbhishek Sharma
2 min read

In this article, I'll guide you through how you can configure your GTM to fire a GMT Tag on meeting different conditions. There were actually multiple ways you can achieve this, but I'll show you the most efficient way of doing this in GTM.

So I was working with a client where we developed a Custom Signup flow, which included 4-6 pages to complete the signup flow. The main requirement that he had, was to fire a GTM tag based on URL Path.

The most basic way of solving this is to create multiple triggers inside GTM based on different URL paths, so in our case, we need to create 6 triggers with the same condition.

image.png But this wasn't the most efficient way of solving problems, because, in the end, we are just repeating ourselves. And being a developer our main goal is NOT TO REPEAT OURSELVES.

So how can we solve this?

We can use something which is called a Single trigger with Regex (or Lookup) Table Variable

At first, it might sound complicated thing to implement, but believe me, it's not.

Follow me to do this:

๐Ÿ‘‰ 1. Weโ€™ll create a Regex Table Variable, In the Google Tag Manager interface, go to Variables > User-defined Variables > New > Regex Table.

image.png

๐Ÿ‘‰ 2. Now select "Input Variable", in our case we are working with Page Path, after that click on the Advanced Settings and uncheck all three options

image.png

๐Ÿ‘‰ 3. Then click Add Row and add the conditions. In the left column, enter /path1. In the right column โ€” โ€œtrueโ€ (without quotation marks) NOTE: (this is just an example. You need to enter YOUR conditions here)

image.png

๐Ÿ‘‰ 4. Repeat the same process for each condition/page.

image.png

Hereโ€™s how the Regex table variable will work: it will start checking the conditions from the top row to the bottom. Once the condition is met, further rows will not be checked.

Now to configure this with GTM Trigger. Go to Trigger Add a New Page View Trigger, select fire on some specific view, and Select your Regex Variable from the dropdown and make it equals to true.

image.png

That's it. Congratulations ๐Ÿฅณ, Now you can configure your Tag based on the Trigger that you've created just now.

image.png

If this article helps you solve your issue or you have further questions, doubts, or want to discuss anything about web development, you can connect with me on.

Thanks ๐Ÿ˜Ž๐Ÿ™

0
Subscribe to my newsletter

Read articles from Abhishek Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhishek Sharma
Abhishek Sharma

Web App Developer