skip to main content

TAMU Webmaster's Blog


Information and insight from the A&M Webmasters

Blocking Triggers in Google Tag Manager

August 17th, 2017 by Erick Beck

In looking at how to optimize our sites download time, one common recommendation is to combine all javascript into a single file.  An even better piece of advice – if there is javascript that your site doesn’t need, don’t download it in the first place.

One of the areas that we identified as being bloated was how we ran our HotJar heat map implementation through Tag Manager.  HotJar tags require an individual id number corresponding to the site being monitored.  Since we have several dozen sites, that means several dozen tags.

The default for tags is to run on all pages.  This meant that all of our sites were firing off all of the HotJar tags, regardless of whether they were even for the proper site.  Realistically that might not amount to much, but I knew we could do better.

One solution might have been to create different triggers for each site, but that would have quickly become unwieldy.  After stumbling across an article talking about trigger exceptions I decided to go down that route.  I first created a variable “Block Sites” with the value of “block” (it could have been “1” or “true” or whatever.)  From that I created the trigger “Block All Sites” that consisted of the simple comparison “When Block Sites = block” (in essence, “when 1=1”.)   The key is to then add this as an exception to your exiting tag firing triggers.  So the tag fires normally if the exception is not present, but does not fire at all if the exception is present.

In theory, since exception prevents the tag from firing, your page never downloads and runs the code associated with the tag.    We do not continually run HotJar, so we can keep the exception in place until we are ready to start collecting data. Then all we have to do is edit the tag to remove the trigger exception and publish the new version.

I do believe there is another way that eliminates even this through the use of an all-javascript trigger, but I’m not myself adept enough with javascript to get all the pieces put together.  I will post at least the first part of the process in a later post that doesn’t include the requirement to match the HotJar id value.

Tags: , ,

Thursday, August 17th, 2017 Analytics
Share this article

No comments yet.

Leave a comment

Categories

Archives