Recently I added support for
gtag.js to CAOS. To be honest I didn’t really think it through. Many people asked for
gtag.js support and me being the obedient soldier that I am, I just implemented it. The update was received with (virtual) standing ovations and… panic. Riots in the streets. WORLDWIDE C-H-AOS! (wink wink) Also, questions. Because what’s the difference between
gtag.js!? Well, let’s find out!
First… A History Lesson
Google Analytics has been around since (almost) the beginning of the internet. Since then the internet has evolved and (luckily) so has Google Analytics. I don’t know how it was implemented back then, because I didn’t start using Google Analytics until 2009, right around the time when
ga.js was released.
The implementation of Google Analytics didn’t change much. The implementation of
analytics.js was basically the same as
ga.js. Until 2017, when
gtag.js was released promising a more unified solution to integrate Google’s different platforms, e.g. Analytics, Campaign Manager and Ads.
So what’s the difference between analytics.js, gtag.js and ga.js?
The short answer is: features. *Uh, spoiler alert!*
The internet has evolved and so has its users. Data is a currency nowadays and Google (one of) the exchange(s).
So for you to decide which file to choose, the question would be: what kind of data are you interested in?
The Wait is Over.
Get the Newsletter you've always wanted, now!
Sign up to receive Biweekly, Free Optimization Tips for WordPress.
No spam. I promise.
What kind of Google Analytics user are you?
Google Analytics is an advanced and flexible application created to fit into any use case. One recent example is how easy it is to confgure Google Analytics to be GDPR friendly. This is probably the simplest example, gathering the least data. But its possibilities are pretty much endless.
The difference between
gtag.js follows this logic.
ga.js being legacy code, has the smallest footprint and the least features.
analytics.js has gained an enormous audience since its release in 2013, and has a complete feature-set compared to its predecessor.
gtag.js is like
analytics.js, but makes it easier to integrate other services. A clear cut difference.
To be honest, there’s no good reason to use
ga.js anymore. Google is keeping it around for legacy, but hasn’t maintained it since 2014. There’s a good chance you can’t use any of the features added since then e.g. Enhanced Ecommerce.
Some people use
ga.js, because they don’t need Google Analytics’ enhanced features. They feel using
analytics.js would unnecessarily expand their codebase.
If optimisation is your argument for using
ga.js, you’re still better of using
analytics.js. Its userbase is waaay (!) bigger, meaning there’s a good chance your visitors already have the file saved in their browser cache. The opposite is true for
Advanced: analytics.js (recommended)
The title says it all.
analytics.js supports the entire featureset of Google Analytics. This means it is suitable for regular, advanced and even professional users. It is actively maintained and will be in the future.
For CAOS users I also recommend to use
The keyword here is integration. If you’re using more Google services besides Google Analytics, then use
gtag.js. This is the only valid reason to use
Keep in mind that it is a wrapper library around
analytics.js and not a replacement. In other words:
analytics.js will still be loaded by
gtag.js adding an extra request to your website’s footprint.
For those who care about their Google Pagespeed and/or Pingdom score, don’t use
gtag.jsis loaded with your Tracking ID as a query string (e.g.
?id=UA-1234567-1) it discourages the browser to load it from cache. In contrast,
analytics.jsis used (without query strings) all over the internet and is therefore widely available from browser cache.
gtag.js‘ filesize is ~60KB and it still loads
analytics.js, which is ~30KB. In other words, if you’re only using Google Analytics and nothing else, you’re adding 90KB (instead of 30KB) of code for the same features.
In most situations I would discourage CAOS users to use
gtag.js, since it goes against CAOS’ core principle: optimisation. Since it’s a wrapper library, it will serve
gtag.js from your server, and still request
analytics.js. Since version 2.5.0, CAOS caches both files when using
gtag.js to deliver maximum optimisation.
In this post I’ve discussed the differences between
gtag.js. I’ve given several arguments to help you decide and recommended the usage of
analytics.js — also for CAOS users — for two reasons: performance and availability of features.