#GTMTips: Track JavaScript Errors as Events

Back back to the friggin’ basics. Almost two years ago, I wrote a two-parter on how to have fun with Google Tag Manager: Part 1, and Part 2. The first part had a nice exercise for tracking JavaScript Errors as Google Analytics Events, using the recently published “JavaScript Error Listener” Tag. Well, that was in GTM V1. Now we’ve been smoothly sailing with the wonderful new interface for well over a year, and it’s time to update some of these nifty tricks. Read More…

#GTMTips: Prevent Tag From Firing in IFrame

Unfortunately, iFrames still exist. They are used to embed content from one page into another. Frames are horrible, nasty things, very often riddled with cross-domain problems, performance issues, responsive design obstructions and other crap from the nether pits of hell. Regardless, if you’re stuck with an iFrame which also collects data to your Google Analytics property, for example, you probably want to prevent at least the first Page View from firing, since otherwise you’ll be double-counting Page Views: once on the main page and once in the iFrame. Read More…

Spam Filter Insertion Tool

Last weekend, I wrote a very simple web app that automatically creates a number of referral spam filters to tackle the problem that seems to have everybody all riled up. For a nice recap of the situation, take a look at this post by Jeff Sauer, or this article by Mike Sullivan. This isn’t an opinion piece, even though I’ve got a great number of opinions about this issue. Read More…

Universal Analytics Plugins Explained

There are many tools and methods to make Google Analytics more manageable. Google Tag Manager is probably the best known of these, and you can find many, many articles about GTM on these pages as well. However, today I want to tell you about one of the features of Universal Analytics that hasn’t, as far as I know, received too much attention. It’s funny, because at the same time almost everyone uses the feature in the shape of eCommerce, enhanced link attribution, and cross-domain tracking. Read More…

Send Weather Data to Google Analytics in GTM V2

In 2013, I wrote a guide for Universal Analytics and Google Tag Manager on how to poll for weather conditions, and send this information to Google Analytics as a custom dimension of the session. The guide was intended as a technical introduction to Google Tag Manager, and I think it succeeded in that. However, GTM has changed a lot over the last 1.5 years, and I’ve made some improvements to the method along the way. Read More…

Leverage UseBeacon and Beforeunload in Google Analytics

This nifty little solution will let you calculate the time spent on pages that are not tracked in Google Analytics by default. These include both bounced landing pages and exit pages. Bounced pages and exit pages lack the necessary subsequent pageview, which Google Analytics uses to calculate time-based metrics. Before you go on, read this excellent article by Yehoshua Coren: REAL Time On Page in Google Analytics Yehoshua gives a very nice use case for the technical solution I’m about to explore. Read More…

Track Non-JavaScript Visits in Google Analytics

One of the big mysteries in browser-based data collection platforms like Google Analytics is what happens when the visitor is not being tracked. This is most obvious in cases where the user explicitly opts out of tracking, when the user does not have JavaScript active in their browser, in bounced sessions, and on exit pages. Opt-outing means that the user explicitly prohibits a website from tracking them. In some cases, it’s possible that opt-out is the default, and the user must explicitly opt-in to allow GA to record their visits. Read More…

Use Page Visibility API With GTM

The Page Visibility API for web browsers is pretty sweet. It lets you poll, using some new properties of the document object, whether or not the current page is visible to the user. Visibility is hidden if the page is not open in the current browser tab instance, or if the browser window has been minimized. In this post, I’ll give an example of how features of the Page Visibility API could be used with Google Tag Manager. Read More…

#GTMtips: Undefined Dimensions Won't Get Sent

This might not sound like a tip to you. You might think, “Dimensions won’t get sent? Sounds like a bug!”. You’re wrong. This is one of the awesome features of the GA API, and it’s key to making your tag setups leaner when sending data to Google Analytics. Tip 4: Undefined dimensions are left out of GA hits Note that ‘undefined’ here means the special value undefined in JavaScript. Read More…

Persist DataLayer in Google Tag Manager

(Update 19 November 2018: See this article for a more elegant solution.) If you know your JavaScript, you know that all variables, functions, objects, resources, and data in the document get rewritten with every page load. In other words, every single page refresh builds the page from scratch, and the state of the document before the page refresh is left drifting in the ocean of oblivion. Google Tag Manager’s dataLayer is also one such entity. Read More…