What Is gtag.js with Google Analytics and Do I Need It?

/

If you have attempted to add Google Analytics tracking code to a website recently, you may have noticed something new – a completely different Google Analytics snippet that looks like the code snippet above.

There has been some confusion around what exactly this ‘gtag’ snippet is for. This article should help clear things up and help you decide if you need gtag.

What is A Global Site Tag (gtag.js)?

Over the years, Google Analytics has released several versions of its JavaScript library, with each one introducing new features and becoming the new recommended implementation. However, this is not quite the same thing. It’s not just another analytics library – the “Global Site Tag” is designed to simplify and streamline website tagging for all Google products.

Geared towards websites that are using on-page tracking code for various tools like Google Analytics and Google AdWords, gtag.js marks a fundamental shift in the way we collect data. It is a new style of implementation where the ultimate goal is to have one centralized script tag that is capable of sending data to all of your Google marketing and analytics tools at the same time – so you no longer need to spend hours configuring tags on your site.

It is not an entirely new library for Google Analytics alone – in fact, behind the scenes it is merely loading in the existing analytics.js library, along with other libraries depending on what tools you configure, such as conversions.js for Google AdWords.

In the past we talked about upgrading from Classic Analytics (ga.js) to Universal Analytics (analytics.js) and compared that to switching out the engine of a car; exchanging a v6 (Classic) for a v8 (Universal), for example. Migrating to gtag.js is completely different – you’re still working with the same v8 engine of the analytics.js library, you’re just using it differently. Maybe we can compare this to simply tuning or reprogramming the existing v8 engine…

There are a lot of interesting opportunities that come with gtag.js, and you may want to plan your migration so that you can take advantage of those as they become available, but there is no need to rush into this migration.

But Wait – Didn’t We Just Start Using Google Tag Manager?

It’s important to note that using gtag.js is not necessary if you are already using Google Tag Manager. If you are using GTM already, continue to do so. In fact, we still recommend upgrading to GTM from on-page code for a number of reasons, linked below, but if you must on use on-page code, read on.

How Does it Work?

Take this example, where a typical website may have the following installed:

  • Google Analytics pageview tracking code on every page
  • Google Analytics event tracking for certain interactions of interest
  • Google Analytics ecommerce tracking for purchases, checkout steps, and more
  • Google AdWords conversion tracking for purchases or lead form completions
  • Google AdWords remarketing tags for building audiences in AdWords

That’s FIVE different script tags for Google products alone!

Gtag.js makes this entire process much easier by:

  • Encouraging you to keep many of the tags for Google products in one place in your code
  • Simplifying installation to get you up and running with Google products sooner
  • Opening up the opportunity to send data to multiple tools at once, rather than requiring separate tags

For example, if you’re using Google Analytics and Google AdWords, your gtag.js snippet would look like this:

The gtag.js code would be placed on each page of your website. config is a command that pulls in the corresponding library for the product configured, such as analytics.js for Google Analytics or conversion.js for Google AdWords.

These config commands also take care of some initial setup items like triggering a pageview hit for Google Analytics or a remarketing hit for AdWords. You can prevent this default behavior by updating the config line as such:

gtag('config', 'UA-66848305-11', { 'send_page_view': false });

Be careful of this if you choose to add new AdWords conversion tracking to your website, for example, as AdWords is now providing gtag-style setup instructions!

There will also be some changes in the way you set up event tracking, ecommerce, cross-domain tracking, etc. for Google Analytics, as well as conversion tracking for AdWords. All of that can be found in the documentation for gtag.js for Google Analytics and Google AdWords.

Do I Need Gtag?

So should you upgrade? We suggest using the following flow chart to see if you should consider using gtag.js.

Are You Adding Tracking To a New Website?YesNo
We recommend that you implement Google Tag Manager instead of using the gtag.js implementation instructions. If you can use GTM, then you do not need to worry about gtag!
You do not need to implement gtag.js! We still prefer Google Tag Manager and believe that tag management systems are the way to go because they provide far greater flexibility in comparison to on-page code.
If you need on-page code for a new site implementation, then you should consider the gtag.js instructions. This will load the latest version of Google Analytics (Universal) and will provide the most flexibility with other Google products.
Universal: No need to rush, but you have the option to upgrade. The analytics.js library is not going anywhere, and gtag.js is loading in this library anyway – so it will offer the same exact functionality with just a different style of implementation. Take your time reviewing the options and your current setup – if you feel you could benefit from the gtag.js style of implementation, start planning the switch!
Classic: Come on now… It’s well past time to upgrade to Universal Analytics, so you might as well do so through following the gtag.js implementation instructions!

Remember: If you are currently using on-page analytics.js, there is no need to rush into migrating to gtag.js. The amount of work it will take to do so really depends on your implementation.

Also, you can still install analytics.js if you need to. Visit the analytics.js documentation.

Amanda Schroeder is a Senior Consultant and comes from the marketing industry where she found a need for accurate, insightful data that could aid in making results-driven decisions. Amanda’s passion for building solid measurement strategies and connecting all the pieces of integrated digital and traditional marketing campaigns has led her to her current role at LunaMetrics.

  • Thanks for the overview, Amanda. This summer, all of my clients’ Google Analytics accounts were in beta – GST for all accounts – and it was hard to find anything about Global Site Tag (Twitter search saved the day). It’s all we have to work with, so implementation is happening quickly on our end. Google testing tools have finally caught up, too.

    Developers are implementing it in various parts of the section, even though they’re instructed to install it at the very beginning. We haven’t seen any problems so far, but could there be down the road?

    • Amanda

      Hi Janet,

      Installing gtag.js high up in the HTML is recommended as it allows the script to fire as quickly as possible (this is the same recommendation for all of the asynchronous tracking options, such as analytics.js as well). If you were to install it lower in the or even in the body, it would simply be loaded later on the page – the implications of this can vary depending on the complexity of your site. For instance, if you have a lot of custom scripts in the that are being evaluated prior to the gtag.js script, it may not fire as quickly as it could if it were higher up in the page.

      • Thanks for the info, Amanda. I suspect some of the installs are auto-placed by WordPress and plug-ins that aren’t configured for GST. It will take time for everything to catch up…meanwhile, will try to catch those that would be impacted by custom scripts. Thanks!

  • Hi Amanda,

    Very nice Post!
    Just to clear that only websites using universal script, should move to GTag but I rather prefer to move to GTM.

    All of my customers are using or moving to GTM

    Best Regards,
    Jorge Cunha

Contact Us.

LunaMetrics

24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.