Recently Google Analytics has quietly released into Beta a new unified site tracking tag called gtag.js.

Note: If you’re currently using Google Optimize, or other additional Google tags, consider using Google Tag Manager instead of the new gtag implementation. As of October 2017, gtag is less powerful than analytics.js in terms of allowing for additional plugins to be used in Google Analytics.

This isn’t an upgrade like we’ve seen before – from Urchin to Classic Analytics and Classic Analytics to Universal Analytics. In fact, it’s clear from the tag code that the script is interfacing with Universal Analytics anyway.

What this new release is clearly hoping to achieve is a unified tagging method that can, in time, combine tag requirements for Analytics, Content Experiments (most will now be using Google Optimize) and also conversion.js.

It’s code footprint is a lot smaller than analytics.js – and many default settings are rolled in. For example, gtag.js automatically sends pageviews to Google Analytics unless you override this – something which required an additional line of code in previous tag versions.

Here’s the basic setup code here:

Should you migrate to gtag.js?

The new Global Site Tag is currently in Beta and as such isn’t covered by an SLA. Also, being in Beta means that there’s a slight chance of future changes, too, so we’d recommend holding on this right now.

If you are still using native analytics.js direct in your application then perhaps instead right now you might want to begin a Google Tag Manager implementation as the dataLayer principle is clearly being brought forward into gtag.js anyway. This would ensure that your tag migration planning is moving in the right direction to access new features as they’re being released, plus would no doubt lead to a much needed tagging cleanup project anyway.

New: Recommended events in gtag.js

I’ve found the new event tracking methods the most interesting change between analytics.js and gtag.js. For one, the new syntax more closely resembles a dataLayer push event, but also, there is now a list of recommended events which can be fired which coincide nicely with Analytics’ Goal setup menu.

These recommended events now include transactions, lead generations, form fills, logins, shares, and a variety of enhanced ecommerce events we’re already used to (add to cart, add to wishlist, add payment info, checkout process begin, etc).

Google Tag Manager and/or Global Site Tag?

If you’re already using Google Tag Manager then a migration right now is not necessary. The new Global Site Tag will not replace Google Tag Manager (GTM), as the purposes here are very different. A Tag Manager suite, like GTM gives separation of concerns from site code and tag management – and adds in tag governance and the ability to trigger additional external tags outside of the Google ecosystem at the same time.

As Global Site Tag interfaces with the dataLayer and, via proxy, the full Google Analytics suite anyway, no additional benefits will be gained by supporting a gtag.js installation alongside GTM (correct as of August 2017).

If you are currently not using GTM and have no requirement for tighter control over tag management, then now is a good time to begin planning your migration to the new gtag.js, as it will no doubt soon be out of Beta.

If you’ve any questions about this new tag, let me know in the comments below!

Aaron Dicks

Performance Director

Performance Director of Impression. Search engine optimisation, paid media and web analytics consultant. Also programmer and digital all-rounder. @aarondicks

Aaron has specialist knowledge in SEO, PPC and Analytics Consultancy.

14 thoughts on “Google Analytics releases new unified ‘Global Site Tag’ – gtag.js

  1. Samrat Mehta says:

    This is a nice piece of info.
    However, I am little in 2 minds since this is in beta state right now.

    So here’s my question:
    Can I go ahead and paste both the snippets, (gtag.js) and (analytics.js) as well? Will this lead to reflecting double of all the numbers across all the metrics since there are 2 codes working in parallel?


    1. aarondicks says:

      Hi Samrat, you’re correct in identifying that this would lead to potentially a double counting issue.

      I think at this stage it would be more beneficial moving towards a GTM integration so that you go through the process of a dataLayer setup first. Then as gtag gains in popularity, you could then look at a further migration once the product becomes more feature rich.


  2. Jess Carranza says:

    For the benefit of those using Facebook Instant Articles, the gtag.js tracking code can be used with Instant Articles. But you have to add one line of code to make it really useful, as follows:

    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments)};
    gtag(‘js’, new Date());

    gtag(‘set’, ‘page_title’, ‘Instant Articles: ‘+ia_document.title);

    gtag(‘config’, ‘UA-XXXXXXXX-X’);

    More details on my blog post:

    1. aarondicks says:

      Thanks for the contribution Jess!

      1. Jess Carranza says:

        You’re welcome. 🙂

  3. geotso says:

    Well, I don’t know javascript and I’d like to call gtag.js from an external .js file. I’ve tried to leave the first line “script async…” under the title tag in html code and move the rest script in an external js file without the tags (lines 3 and 9 in the above example of yours). However Dreamweaver finds errors like “line 5: ‘dataLayer’ is not defined”.

    What am I doing wrong?


    1. aarondicks says:

      I wouldn’t suggest running local gtag scripts just yet as this may be subject to change.

      But to resolve your issue, just implement the following line on your page before you call this external script, to define the variable ahead of its use if it hasn’t been initialised just yet;

      var dataLayer = dataLayer || [];


  4. Oliver says:


    I cannot find ANYWHERE on the web that you can use the new Global Site Tag with Google Optimise. Even on the Optimise instructions for the plugin, it shows the old UA code and not Global Site Tag, so it’s unclear where you’d even insert the GA code for Optimise in the existing Global Site Tag code?

    For some reason, Google Optimise is causing a 90% bounce rate on our site and I just cannot figure out why as even a cross browser check reveals no obvious issues. Was hoping maybe that changing to Global Site Tag might help solve this?

    PS – Google Analytics now (Oct 2017) doesn’t even give you the code for UA anymore, just Global Site Tag.

    1. aarondicks says:

      Hi Oliver,

      I’ve taken a look and think you may be correct. I mentioned in the article that this is still new so may not work with everything.

      It may be best to continue your deployment of Optimize via GTM as detailed here:

      It appears to only presently work as a GA plugin (via ‘require’) or a GTM deployment per this link.

      gtag currently only has three comments listed in the documentation and none of these look useful for Optimize at this stage:

      Sorry I can’t be more help! If you’d like to get in touch directly we can take a quick look and see whether you’re experiencing another underlying JS error, though. Perhaps that will help?

      Thanks for your comment, Aaron

      1. aarondicks says:

        Also @disqus_Tc5LLDqpfj:disqus – have you tried a Google Optimize deployment via Google Tag Manager?

        This may solve your issues with deploying multiple tags on your website, and it’ll sandbox your remote tags meaning any on-site JS errors can be debugged a little easier, too.

        Given all options, it’d probably be my preference to run everything though GTM or similar.


  5. Bridget says:

    Thanks for the info Aaron – there isn’t too much out there so this is much appreciated! I’ve just got a new client on board. They are using analytics.js for Google Analytics. For Adwords, we are setting up a new conversion (destination thank you page). We now have to implement not only tracking code on this thank you page, but also a universal adwords script that looks something like this:

    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());

    gtag(‘config’, ‘AW-XXXXXXXXX’);

    My concern is that Adwords will then be using the global tag, and Google Analytics will then be using the analytics.js tag. Do you foresee this to be a problem?

    1. aarondicks says:

      Hi Bridget, thanks for the comment

      It sounds like you’d be best served by using a Google Tag Manager (GTM) deployment, rather than this gtag one. gtag is a replacement for the analytics.js tag, but through using Google Tag Manager you can contain all tags in one place.

      Also, through GTM you’ll be able to add in your triggers for the thank-you page, too!

      Hope that helps?

      1. Bridget says:

        Thanks Aaron, yes that makes sense. Much appreciated 🙂

  6. Daniel Velasquez says:

    how to send custom dimension?

    i send gtag(‘config’, ‘UA-111-5’, { ‘user_id’: 123456});

    my inconvent is Tag Assist indicates me “Same web property ID is tracked twice”

    To clarify,
    when loading the send page:

    window.dataLayer = window.dataLayer || [];
    function gtag() { dataLayer.push(arguments); }
    gtag(‘js’, new Date());

    gtag(‘config’, ‘UA-111-5’);