skip to main content

TAMU Webmaster's Blog


Information and insight from the A&M Webmasters

tag manager

Blocking Triggers Refined

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 No Comments

Blocking Triggers in Google Tag Manager

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 No Comments

Categories

Archives