#GTMTips: Track Outbound Link Clicks in Google Tag Manager

I’ve written about outbound link click tracking before. It’s a very solid way to track interactions on the site, as clicking a link that leads away from a site is a signal of … well, something. In Google Tag Manager it’s now extremely easy and efficient to track outbound link clicks, thanks to the introduction of a new configuration in the Auto-Event variable. This article will introduce the new method and show you how you can quickly set it up! Read More…

#GTMTips: The Mysterious .Macro() Call in Custom HTML Tags

When previewing Custom HTML tags in Google Tag Manager you’ve almost certainly run into a situation where the GTM variable shows up as a weird JavaScript method resembling something like this: google_tag_manager["GTM-ABCD123"].macro(15) And this is when you were expecting it to show the actual, resolved value! It doesn’t help that every now and then the preview mode actually shows to correct value in the preview mode. What’s up with that? Well, there’s a fairly logical explanation to this. Read More…

#GTMTips: When Click Variables Are Undefined

A surprisingly common question in forums and communities seems to be why the built-in Click variables show up as undefined in Google Tag Manager’s Preview mode, even if you click around the site. In this article, I’ll walk you through some of the reasons why this might happen. Tip 104: What to do when Click variables are undefined Here’s the situation: you want to create a Click trigger for your tags, but in order to do so, you’d need to see what values the built-in Click variables (e. Read More…

#GTMTips: Get Latest Exchange Rates for Client-Side Conversions

It’s been a while since I’ve last written a bona fide Google Tag Manager trick, so here comes. This was inspired by Bart Gibby’s question in Measure Slack. The purpose is to fetch the latest currency exchange rates from the exchangeratesapi.io service, cache them using sessionStorage, and push the results into dataLayer. From dataLayer, they can then be utilized in Custom JavaScript variables and custom variable templates to perform client-side conversions. Read More…

#GTMTips: Enable Preview Mode in the Safari Browser

With Intelligent Tracking Prevention, the Safari browser is on a crusade against cross-site tracking. One of the most obvious and long-standing ways to battle cross-site tracking has been to block third-party cookies in the web browser, and this is exactly what Safari does by default. However, Google Tag Manager’s Preview mode relies on a third-party cookies, so that it can serve you the draft version of the container while serving the regular, live container to your site visitors. Read More…

#GTMTips: Introducing the GTM Templates Library

When Custom Templates were released in Google Tag Manager, many of us active in the GTM communities started doing two things: 1) creating our own custom templates, and 2) waiting patiently for Google to release a “gallery” or “library” for distributing these community contributions. While I have full faith in the latter happening some time in the future, I thought it would be fun to create something similar to a library, and then open-sourcing it for the community to help out with or to download locally for their own purposes. Read More…

#GTMTips: Send Page Visibility State to Google Analytics

One of my pet peeves about Google Analytics has to do with nomenclature. For example, a User isn’t really a user but a browser instance, and Direct traffic isn’t necessarily “direct” at all, but rather just traffic that has no discernible source. But being so invested in content analytics, my biggest gripe has to do with Pageviews. A Pageview in Google Analytics is collected when a hit with the hit type pageview is received successfully by the Google Analytics endpoint. Read More…

#GTMTips: Create Facebook Pixel Custom Tag Template

After the recent release of Custom Templates for Google Tag Manager, my mind has been occupied by very little else. However, I have a nagging feeling that due to how involved the feature set is, there’s still a lot of demystifying that needs to take place before templates are fully embraced by the GTM user base. In this article, I want to show you a concrete example of template creation. It’s going to be much more ambitious than the simple walkthrough I explored in the main guide. Read More…

#GTMTips: Fetch the Latest Value of a Data Layer Variable

One of Google Tag Manager’s oldest and most reliable features is that it freezes the state of Data Layer variables to the moment when the trigger event occurred. Thus, any tags firing on this trigger (and any variables resolved on this trigger event) will always have access to the same value of each Data Layer variable. However, there are situations where this is not a good thing. One is tag sequencing, and the other is a scenario where you want to run some custom code that should access the latest value of the Data Layer variable at a moment in time after the tag has already fired. Read More…

#GTMTips: Create Utility Variables by Returning Functions

In Google Tag Manager, the Custom JavaScript variable is an anonymous function with a return statement. It does not take any parameters, and by default it’s impossible to pass any parameters to it, because the Custom JS variable is simply resolved to whatever value the function returns. If it returns a number, for example, passing a parameter to it would make no sense and would result in a TypeError since the variable resolves to a number, not a function. Read More…