#GTMTips: Use LocalStorage for Client ID Persistence in Google Analytics

Updated 1 October 2019 With ITP 2.3 it looks like Safari is reducing the usefulness of localStorage as well, so this solution should not be considered future-proof. The only stable way to persist client-side data at the moment seems to be HTTP cookies. Updated 7 March 2019 - Added some extra caveats to this solution. Also, be sure to read my article on ITP 2.1, which has far more detail on what Intelligent Tracking Prevention is and how to work with it. Read More…

True View Ecommerce Impressions With Google Tag Manager

Last updated 9 October 2020: customTask updated to a more stable version. I’m a big fan of Enhanced Ecommerce in Google Analytics. In fact, I think it’s the only valid way to deploy Ecommerce tracking today, especially when using Google Tag Manager. The ability to use a Custom JavaScript variable and the possibility to tackle the full ecommerce funnel are some of the benefits of using Enhanced Ecommerce. Read More…

#GTMTips: Trigger Javascript Function Without Using a Custom HTML Tag

Last updated 9 October 2020: customTask updated to a more stable version. The Custom HTML tag in Google Tag Manager is splendid. It’s your go-to tool when you need to run arbitrary JavaScript on the webpage. Some might even use it to actually add HTML elements to the page, but I’m willing to bet running JavaScript is its most common use. However, there’s a downside to Custom HTML tags, which is only made more apparent on single-page apps which do not clear the full page when transitioning from one state to another. Read More…

Obfuscate and Duplicate Google Analytics Data

Perhaps you didn’t know this, but there’s a really handy demo account for Google Analytics you can use to check out how Google Analytics works in a real business context (the data is from the Google Merchandise Store). However, you can access the account with nothing more than read-only access. This is annoying if you wanted to customize the setup. Worry not, I have a solution for you! Harnessing the awesome power of customTask, you can create a duplicate of the data collected on any website where you can modify the tracking (e. Read More…

Prevent Duplicate Transactions in Google Analytics With CustomTask

One of the big problems in Google Analytics’ data model is the immutability of historical data. Once a row of data is written into the data table, it is there practically for good. This is especially annoying in two cases: spam and bogus ecommerce hits. The first is a recognized issue with an open and public data collection protocol, the latter is an annoyance that can explode into full-blown sabotage (you can use the Measurement Protocol to send hundreds of huge transactions to your competitor’s GA property, for example). Read More…

How to Unset a User-Scoped Custom Dimension in Google Analytics

Scope in Google Analytics’ Custom Dimensions refers to how the value in the Custom Dimension is extended to all hits in the same scope. Hit- and product-scoped Custom Dimensions apply to the given hit alone - they are not extended to any other hits in the session or by the same user. Session-scoped Custom Dimensions apply the last value sent during the session to all the hits in that session. Read More…

Tracking Cross-Domain Iframes - Upgraded Solution

**Last updated 18 September 2020: Due to how most browsers now have third-party cookie protections in place, this solution will be very ineffective going forwards. You should instead take a look at a cookieless solution. Some years ago, I wrote a post on how to track cross-domain iframes when using Google Tag Manager and Google Analytics. That solution relied on hitCallback to decorate the iframe, and now that I look back on it, it has its shortcomings. Read More…

Create and Update Google Analytics Session Timeout Cookie

In Google Analytics, the concept of a session is the key aggregation unit of all the data you work with. It’s so central to all the key metrics you use (Conversion Rate, Bounce Rate, Session Duration, Landing Page), and yet there’s an underlying complexity that I’m pretty certain is unrecognized by many of GA’s users. And yet, since this idea of a session is so focal to GA (to the point of being overbearing), it’s annoying that the browser isn’t privy to any of the sessionization parameters that Google Analytics applies to the hits sent from the browser to its servers. Read More…

#GTMTips: Introducing the CustomTask Builder

One of the coolest features of Google Analytics and, as a consequence, Google Tag Manager is customTask. It’s a method you can use to add and execute code as the hit to Google Analytics is being generated. I’ve written A LOT about customTask, and much of the feedback I’ve received has been around the question of how to combine all these different tricks into one customTask script. The problem is, you see, that a tag or hit can only have one customTask script attached to it, so the code within must combine all the different tricks I’ve been writing about over the past months. Read More…

Automatically Reduce Google Analytics Payload Length

Here we are, reunited with customTask. This time, we’ll put this wonderful mechanism to work for a very, very good cause. One of the lesser known “features” of Google Analytics is that when the payload size (the request body that is actually sent to Google Analytics with each request) goes past a certain limit, specifically 8192 bytes, the hit is aborted without warning. This can come as a surprise, because there’s no indication anywhere in Google Analytics that you are missing hits because of this. Read More…