skip to main content

TAMU Webmaster's Blog


Information and insight from the A&M Webmasters

Blocking Triggers Refined

August 23rd, 2017 by Erick Beck

In my last post about blocking triggers I showed how you can use exceptions to prevent Google Tag Manager from firing particular tags.  Because the HotJar tag contains the service ID value for that site we had to create individual tags/triggers for each site.

But what about when you have a more generic tag that is not linked to a particular service ID?  For example, you want to include an HTML or javascript snippet, but you still want to be able to control which sites it is or is-not displayed on.  You could create individual tags/triggers for each site as we did with HotJar, but there is actually a better solution.

The process starts the same, by adding a variable to your GTM.  This time, though, we will use the “Custom Javascript” variable type instead of the “Constant.”  The javascript we use then sets the URL of all of our sites that we want to exclude into an array.  It then loops through the array and tests whether the page being viewed is in that array.  If it is, then the function returns “true.”

At that point we can continue the same process that we showed for the HotJar tags.  Add a trigger that executes when the variable value returns “true” and then make that trigger an exception.  Now you are excluding that tag from firing only on the sites that you put in your javascript array.  To add or remove sites, just update the array in the variable and republish your tag workspace.

There are several other variable types. I have barely scratched the surface.  DOM Element looks particularly interesting.  This or another combination might actually solve the problem of needing duplicate tags for our HotJar implementation.  I will let you know if we ever get that far.

 

Tags: , ,

Wednesday, August 23rd, 2017 Analytics
Share this article

No comments yet.

Leave a comment

Categories

Archives