In 2017, Google added some sneaky articles to their developer website and support website about a new analytics tag called gtag.js:

Add gtag.js to your site

Migrate from analytics.js to gtag.js

Basic web-tracking set-up (includes many “with gtag.js” articles): What do we know about gtag.js?

The existence of gtag.js means that the Google Analytics code is going to change from using analytic.js to using a new tag: gtag.js. That means there is going to be a code update for:

  • Pageview tracking (i.e. “normal Google Analytics tracking”)
  • Event tracking
  • Ecommerce tracking
  • Custom dimension/metric tracking
  • Client/User ID tracking
  • User timings
  • Exception tracking

This means you’ll need to plan to migrate your analytics once again. At the minute, analytics.js is still the operating standard for Google Analytics, and Google have yet to announce when gtag.js will be considered the new operating standard and if analytics.js will become deprecated.

If the migration from analytics.js to gtag.js is similar to the migration from ga.js to analytics.js, I would expect to see:

  • An alert in Google Analytics
  • A dedicated gtagt.js centre within Google Support, similar to the Universal Analytics one
  • The option of a gtag.js tag within Google Tag Manager

The official description of gtag.js from Google:

gtag.js is the web tagging library that works for Google’s site measurement, conversion tracking, and remarketing products – giving you better control while making implementation easier. By using gtag.js, you will be able to benefit from the latest dynamic features and integrations as they become available.”

The web tracking set-up guide includes the new tag format:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');

This code will only be for tracking web pages, not for tracking app usage. However, gtag has been confirmed to support Google Optimize. Google Optimize is currently deployed by amending the analytics.js tag, and will work similarly.

Does gtag.js support Google Optimize question

What can we speculate about gtag.js?

Interestingly, although the code above is a Google Analytics tag, it references Google Tag Manager, so may be able to be used to better tie together Google’s tracking and tag management products.

In this article there is advice to use Tag Assistant to debug the implementation of gtag.js. This suggests that Tag Assistant already has capability to read and understand if gtag.js works correctly.

Looking at Cross Domain Tracking with gtag.js we can infer that it works similarly to cross domain tracking with analytics.js as the same filters and referral exclusions are referenced. Similarly, gtag.js still allows for content grouping via tracking code.

Event Tracking seems to be more powerful than before. There is an example here of tracking outbound links with gtag.js which was possible with analytics.js, but only via correct GTM implementation or good developer knowledge. This kind of event tracking being made more “standard” hints at more common streamlined event tracking via gtag.js.

Should I migrate to gtag.js? What about my data? Will it change?

Google has stated that moving to gtag.js will not affect your data. This is true in priniciple. However, I still suggest creating a migration plan, so that all old code is replaced.

Question regarding moving from analytics.js to gtag.js

As for “should I migrate now?”, I would suggest doing this on a staging website to ensure everything works as expected before migrating your entire code across, or waiting until gtag.js is confirmed to be out of beta. However, it is best to know that this change will come and be prepared to migrate to gtag.js in the future.


Related Posts