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 websites and measurability being implemented in that way. So how can you adapt to 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, 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. |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.


Gtag.js is definitely an improvement over its predecessor analytics.js in terms of data collection. However, 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.


Experience it for yourself

Related news

We build


We build websites, apps or e-commerce platforms designed to trigger your target audience, represent your brand and achieve your goals.
We create


Content is the translation of your brand into images and text. Stay in touch with your target audience through video, copy, social media and influencers.
We spark


Create a plan for measurable growth and find out what you actually earn from your marketing efforts like ads, data, email and so much more.
We provide


Get your team supported by the new generation of marketers, who match your organisation and challenge you with fresh eyes and their personal expertises and skills.

We shape 

Digital Strategy

Achieve goals by positioning your brand smartly.
This field is for validation purposes and should be left unchanged.