What is gtag.js and when should I migrate?


This article is for everyone using Google Analytics or Google AdWords on any of their websites and don’t know much about the new gtag.js, yet.

In this article, I am going to give you a quick overview of what gtag.js aka Global Site Tag is as well as who and when should consider migrating from their current tracking setup.

What is gtag.js

Global Site Tag is here to replace and merge analytics.js of Google Analytics and conversion.js of Google AdWords. So essentially a unified tracking snippet for Google Marketing Suite products.

Here’s what Google itself has to say about it:

The Global Site Tag (gtag.js) provides a framework for streamlined web page tagging – giving you better control while making implementation easier. Using gtag.js lets you benefit from the latest tracking features and integrations as they become available.

You might have already noticed that in Google Analytics, gtag.js is already the default snippet and the old analytics.js is only mentioned in the Additional implementation section at the bottom of the pages. So clearly Google has made a decision here.

Although the javascript library is new, it is still connecting to the same endpoints and sending the same requests to the server. So at this point (and probably for several years to come) your analytics.js setup will work just fine.

Let’s have a quick look at the snippet itself:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-111449221-1"></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-111449221-1');

As you can see, it is using the same dataLayer object that you might know from Google Tag Manager. In fact, if you take a closer look you will notice that every time you call gtag(), you are actually pushing a set of arguments into the dataLayer.

I mentioned that gtag.js also works for AdWords, let’s connect these two snippets and see how it would look like:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-111449221-1"></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-111449221-1');
  gtag('config', 'AW-1003932562');

And this is how a conversion snippet for AdWords would look like:

<!-- Event snippet for Test conversion page -->
  gtag('event', 'conversion', {
      'send_to': 'AW-1003932562/96o1CNf-t3sQkpfb3gM',
      'transaction_id': '12345'

So, as we can see it does look more compact and more intuitive than the old solution. But is it enough to migrate from your current setup right away?

Who should migrate?

I this paragraph, I am going to cover all of the most common scenarios you might currently be in and try to advise you on whether to migrate or not.

But first, let me quickly give you another option. Gtag.js is great and functions in many ways like Google Tag Manager (GTM). If you are not using GTM yet, and don’t have a very good reason for not doing so, I’d rather move my Google Analytics and AdWords setups there.

Not only does the GTM’s visual interface make everything much easier to maintain, it also prevents you from having to worry about the version of GA snippet.

But now the scenarios:

Currently using ga.js snippet (Classic Google Analytics)

There are still a ton of websites that rely on the legacy ga.js snippet that in most cases still does the job but has been deprecated years ago. You might expect very little third-party support as well as outdated documentation and tutorials.

Recommendation: Migrate (gtag.js or GTM)

Using Google Tag Manager

As mentioned above, GTM is probably the best solution for implementing Google Analytics on your website. It is also highly recommended by Google itself.

Recommendation: Do nothing

Using analytics.js

This scenario is probably applicable to most websites on the web. As this solution is working fine and will continue to be most popular snippet for years (probably), there is no rush for migrating. You have the widest range of tutorials and third-party support.

Recommendation: Look into gtag.js and prepare to migrate in the future or move to GTM

New website or no Google Analytics yet

Unless you have a very good reason not to, you should probably install Google Analytics on your website. Not only will it give you an overview of how many visitors you have but also about their actions and much more.

Recommendation: Install GA using gtag.js or GTM

Using a third-party plugin for implementing GA

There is a variety of tools that promise to make the implementation process easier. The truth is though, that it’s hard to find one that is actually easier than GTM while still giving you the freedom of customisation of pretty much everything.

The only reason could be e-commerce tracking on a specific CRM (Shopify, Woocommerce) where the third-party tool could save a lot of time for beginners.

Recommendation: Unless you’re sure there’s great value in using it, move to GTM.


Gtag.js is a big update in Google Analytics tracking code and will change a lot for some developers and analysts but most of you shouldn’t bother too much.

Unless your setup is broken or outdated, there is no rush in migrating anywhere. If there is something itching, the first thing I would consider is moving the entire setup to Google Tag Manger and if that is not an option, to gtag.js.

PS! You are all welcome to share your opinions about migrating to gtag.js in the comments section below.

4 thoughts on “What is gtag.js and when should I migrate?

  1. Thank you. Another scenario (one that I am in) is: you are using analytics.js in your website and want to add conversion tracking from Google Ads. Google Ad provides a snippet using gtag.js so that your website can tell it when a Google Ad has led to a conversion (eg purchase).

    In that case it makes sense to convert to gtag.js rather than use two libraries (analytics.js and gtag.js) in parallel.

  2. Pingback: Ultimate Guide to Setting up Enhanced Ecommerce Tracking - Reflective Data
  3. You mentioned that GTM implementation handles potential issues with GA snippet version. But maybe you know if standard UA tag in GTM evokes currently gtag.js or still analytics.js library? It seems to me that it still evokes analytics.js.
    Which does not change the fact that it does not matter to most UA implementations via GTM 😉

    1. That is correct, GTM still uses analytics.js (which means it is still a perfectly valid option), and they will most probably start using gtag.js once it has been public for a while and all the bugs have been fixed.

      But yeah, when using GTM, you can leave dealing with the version to Google.

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign up for Reflective Data

5,000 sessions / month ×

Please enter your email


After submitting your email, we will send you the registration form.