Write to Google BigQuery From a GTM Server Container

Ever since it was released that server-side tagging in Google Tag Manager would run on the Google Cloud Platform stack, my imagination has been running wild. By running on GCP, the potential for integrations with other GCP components is limitless. The output to Cloud Logging already introduces interesting pipeline opportunities, but now it gets even better. It’s finally possible to write directly to Google BigQuery from a Client or tag template! Read More…

#GTMTips: The Data Layer Picker Variable Template

There’s a new custom variable template in town! The Data Layer Picker template lets you create variables that have a singular, exceptional (in Google Tag Manager’s context, at least) purpose: You can access the keys and values that were in the object pushed into dataLayer itself. And … that’s it! Read on to understand why this might be useful. Tip 123: Direct access to the dataLayer.push() If you know your Data Layer Variable, you’ll know that it comes in two versions. Read More…

Track Core Web Vitals in GA4 With Google Tag Manager

Updated 3 March 2023: Added a checkbox to the template to enable collecting FCP, INP, and TTFB metrics, too.. Core Web Vitals is described on the dedicated web.dev resource as (emphasis mine): “Core Web Vitals are the subset of Web Vitals that apply to all pages, should be measured by all site owners, and will be surfaced across all Google tools.” The Core Web Vitals measurement as suggested by Google are: Read More…

#GTMTips: Write Client ID and Other GTAG Fields Into DataLayer

One of the big omissions, at least for now, in Google Analytics 4 is the customTask. It is unfortunate, but no such mechanism exists in the client-side SDKs. This means that you won’t be able to do all the magical things that customTask enables in Universal Analytics. One of the biggest headaches is how to collect extremely useful fields such as the Client ID, as these are not available by default in the Google Analytics 4 reporting interface. Read More…

Snowplow Analytics Templates for Google Tag Manager

When custom templates were released for Google Tag Manager, I updated my workflow for working with GTM. Instead of instinctively rushing to the Custom HTML tag and the Custom JavaScript variable, I started considering whether the custom script that needed to be deployed could be transformed into a custom template first. While publishing numerous templates into the community gallery, I always spent some time over the past 12 months tinkering on an extremely complicated template translation: the Snowplow Analytics JavaScript tracker. Read More…

#GTMTips: Collect ISP as a Custom Dimension in Google Analytics

Update 6 April 2020: I updated the template in the gallery to the latest version of the IP Geolocation API SDK, which no longer requires jQuery. Also, the SDK now handles API request caching to browser storage automatically, so the “Enable Session Storage” option was added to the template. Google Analytics had been foreshadowing the deprecation of the Network Domain and Service Provider custom dimensions since late 2019. On February 4, the plug was finally pulled, and both these dimensions started flatlining to (not set) in Google Analytics reports. Read More…

CDNJS Hosted Libraries Template for Google Tag Manager

One of the prime things to use Google Tag Manager for is script injection. Loading a third-party JavaScript library is trivial to do with a Custom HTML tag, and works like a charm. However, using Custom HTML tags for, well, anything, is no longer the preferred way to add custom code to the site. Custom HTML tags are pretty expensive DOM injections, and they can be incredibly dangerous tools (for UX, security, and privacy) in the wrong and/or inexperienced hands. Read More…

Fetch IP Geolocation Data Using Google Tag Manager

Update 6 April 2020: I updated the template in the gallery to the latest version of the IP Geolocation API SDK, which no longer requires jQuery. Also, the SDK now handles API request caching to browser storage automatically, so the “Enable Session Storage” option was added to the template. My latest custom tag template tackles a use case I’ve referred to a number of times before, especially in my article on sending weather data to Google Analytics. Read More…

Persist Campaign Data on the Landing Page

Universal Analytics utilizes two components (by default) to attribute a browser session to a specific campaign: query parameters in the URL and the referrer string. The page URL is sent with every hit to Google Analytics using the Document location field, which also translates to the &dl parameter in the Measurement Protocol. The referrer string is sent with a hit to Google Analytics using the Document referrer field, as long as the referrer hostname does not exactly match that of the current page and the referrer string is not empty. Read More…

#GTMTips: Walkthrough of Custom Template Tests

Google Tag Manager now lets you add unit tests directly to your custom templates. This is useful, since it allows you to control the code stability of your templates, especially if you’ve decided to share those templates with the public. I recently shared a general guide for how template tests work, but I wanted to expand the topic a little, and share with you two walkthroughs of custom template tests: one for a variable template and one for a tag template. Read More…