Google Tag Manager and gtag.js - this is how you do it!

In recent years, a lot has changed in how Google measures conversions and website statistics. To keep up with the developments, Google introduced the new Global Site Tag (gtag.js) as general tracking code in late 2017. Since it is recommended by Google over the traditional analytics.js, we are increasingly seeing gtag.js implemented on the website and measurability being shot in that way. So what about this when you are (already) using Google Tag Manager (GTM)? Can GTM and gtag.js run side by side in harmony, without causing duplicate measurements? They certainly can! Read how to set this up correctly in this blog.

What is gtag.js?

Gtag.js is an Analytics tracking code: a piece of Javascript code that you place on a website, which sends data to Google Analytics. With the advent of gtag.js, a change is taking place in the way we collect data. The ultimate goal is to have one central piece of code that is able to send data to all Google marketing and analytics tools at once. So Gtag.js was created to streamline website tagging for all Google products.

But wait, weren't we just getting started with GTM?

What is GTM?

Google Tag Manager (GTM) is a user-friendly tool that allows users to manage and post their own tags or JavaScript snippets. Only one piece of code needs to be placed on the website, all other tags are then fired through GTM. This makes it easy to place products like Analytics, Google Ads Conversion Tracking and Remarketing, and Floodlight on your website. Instead of placing separate pieces of code on your website, use the GTM interface to decide which actions should take place on which page. You then add these to GTM in the form of 1) tags: a piece of code; 2) triggers: where and when tags are fired and 3) variables: we use to store information from the tags and triggers.

Let's come back to the question of whether we weren't just doing a nice job with GTM. Basically, it is not necessary to put gtag.js on the website if you are already using GTM. After all, the advantages of GTM are:

  • It's free.

  • You can easily make adjustments yourself.

  • The options are endless: GTM can be used for more than just Google products and is easy to customize.

  • GTM makes it easier to implement advanced Analytics features. Think of cross domain tracking, user ID tracking, etc.

  • It is well secured.

  • Debugging options. You can build in error checking and control, so that everything is debugged before it goes live.

How do I make a choice?

GTM and Google Analytics are two separate tools that can be used independently of each other. You can choose to use GTM alone, or you can choose to use gtag.js alone. In general, Google recommends tracking Analytics through GTM. However, this is not always possible. And fortunately, GTM and gtag.js can be used well together, provided you know how to do so.

How do I use GTM and gtag.js together?

More and more we see that new websites are switching to gtag.js. Not surprising, considering Google recommends this tracking code over the old analytics.js. It is also happening more and more that conversions are being shot in via gtag.js. So when this is the case, it means that Analytics is hardcoded on the website. This potentially causes problems if you also want to do measurements via Google Tag Manager (GTM). For example, if you measure e-commerce via gtag.js, but manage soft conversions, such as newsletter subscriptions, via GTM. It can also cause problems when websites require both Google Analytics and GTM for extensive advanced Analytics tracking (Shopify, we're looking at you).

When you want to use both GTM and gtag.js, you run the risk of duplicate measurements. Analytics can run through both, which is problematic. A large part of the GTM tags are based on an Analytics variable. This means that you probably have Google Analytics as a tag in GTM. And if there is also gtag.js on the website, this most likely means that there is double data coming in. Is there a way to have both Analytics and GTM on the website without duplicate data? The answer is yes.

The solution is to make sure that no Analytics 'Page View' is being fired from GTM. This means that you should not use the below (default) implementation of the Analytics tag in GTM:

You can still use a Universal Analytics tag in GTM that is fired on all pages. But instead of using tracking type 'Page View', choose tracking type 'Event' (see example below). This will eliminate duplicate page views, as you will have one pageview fired (gtag.js) and one event fired (GTM). You can see this event in the 'Behavior' section of Google Analytics.

Conclusion

Gtag.js is definitely an improvement over its predecessor analytics.js in terms of data collection. But when you have the chance to set everything up through GTM, that is still the preferred option. If this is not possible, you can certainly use gtag.js and GTM side by side, but make sure that only one pageview is fished. That way you avoid duplicate data and can take advantage of the benefits of both gtag.js and GTM.

6 digital agencies join forces under one name: Endeavour

Until recently, digital agency Endeavour had several agencies under its name, such as influencer agency 3sixtyfive and online marketing agency DBOM. From now on these names will no longer be used, as the six different agencies are continuing together as one, under the name Endeavour.

5 tips for powerful data-driven brands

Exceptional branding takes time and proper investments. But what has happened to brand awareness in recent times? Are data and branding incompatible? Or do they exist in harmony? Below we give 5 tips to make sure you market yourself powerfully with badass marketing. Let's go!

NFTs as new holy grail for brands and influencers?

NFTs and influencer marketing go hand in hand. NFTs are basically a new business model that allows you as an influencer to generate new revenue streams. How? Read it here!

Martijn Berns

Managing Director Growth & Partner

Curious how we can help you?

Contact us