What we know about gtag.js, the new Google Analytics Global Tracking tag

Author avatar

Emma Barnes

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="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');
</script>

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.

via GIPHY

Bath

+44 (0) 1225 480 480

20 Manvers Street

Bath

BA1 1JW

Leeds

+44 (0) 113 260 4010

2nd floor, 2180 Century Way,

Thorpe Park,

Leeds, LS15 8ZB.

London

+44 (0) 113 260 4010

5th Floor, Cordy House,

91 Curtain Road

London, EC2A 3BS

Part of the St. Ives Group

  • By pressing submit you consent for Edit to contact you via your email or telephone number for purposes relevant to your request for our goods or services. Your contact details, including your name, company, telephone number and email address will be used by Edit. By contacting you are agreeing to Edit’s Privacy Policy. If you have any questions, please ensure you review this section before submitting.

  • This field is for validation purposes and should be left unchanged.

© 2018 Edit. St Ives Group. Company reg. no. 3624881, All rights reserved. VAT Registered GB 927458295 Privacy Policy | Terms & Conditions | Cookie Policy