Google Tag Manager has many great features when it comes to firing or blocking tags. As you might already know, blocking rules only work when they are defined on the same level as the tag you (might) want to block.
Most used levels for triggers are probably Pageview, DOM Ready, Window Loaded or on an event. So, how do you make sure that your blocking rule works for ALL the tags that are being loaded in the Tag Manager? As an example i will use a popular blocking rule: the one to check if the users accepted cookies or not. Especially with the GDPR coming up in a few months it's good to make sure that you are not storing personal data or building audiences before the user gave a consent for this.
What not to do
So, what i saw happening in a lot of GTM containers: several blocking rules on different levels:
- DOM Ready
- Window Loaded
- Event -> name of the event
For the first three levels, creating separate triggers / blocking rules seems to be a good solution, you only have to copy the first blocking rule and change the levels and make sure the right level of blocking rule is applied to the tag. When looking at the other level blocking rules, they are often created for one specific event, click or link click.
As you can imagine, your existing blocking rules might not cover all your existing GTM events.
How to fix this
After noticing segment pixels being fired without a valid consent by the user I started looking for a better solution to create blocking rules. Then I learned about the very powerful RegEx functionality within the event blocking rule.
If you are familiar with RegEx, you will recognize the expression
.* which you use to match anything. In this case, the blocking rule will match every level and will make sure that the tags don't fire if the cookies aren't accepted.
In addition to making sure you blocking rules work properly, this solution also helps you with:
- minimizing the amount of triggers you need
- minimizing the amount of mistakes because you only have to adjust one trigger.
Do you also have some great efficiency ideas for Google Tag Manager? Please leave a note!