analytics.js, I recently 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!
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)
This is the recommended file to go for, unless you are using more of Google’s services besides Google Analytics.
After Google’s update of the API to v4, I’d still recommend using it, since it isn’t officially deprecated and it’s much lighter in weight (46 KB) compared to
For CAOS users I still recommend to use
analytics.js unless you have reasons to use
Professional: gtag.js (v4 API — beta)
What used to be a wrapper library around
analytics.js now features its own full-fledged API to work with Google Analytics. In other words:
analytics.js will no longer be loaded by
gtag.js (as opposed to its predecessor — which added an extra request to your website’s footprint.)
Before the update I would’ve discouraged CAOS users to use
gtag.js, since it went against CAOS’ core principle: optimisation. Since it’s no longer a wrapper library, it’s perfectly fine to use it — IF you’re using its featureset. Since version 3.8.0, CAOS caches the updated version of
gtag.js to deliver maximum optimisation.
Be aware of the fact that the Measurement Protocol of the V4 is still in Alpha (!). If you use CAOS in Stealth Mode this might cause issues.
I strongly suggest you run UA (analytics.js) and GA4 in parallel for a while, before switching to the V4 API. This way you can compare data, and make sure that GA4 is tracking your site accurately.
For CAOS users, I’ve created a mini plugin, which makes it easier for you to make this happen. It’s available for free on Github.
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 either
gtag.js — also for CAOS users — for two reasons: performance and availability of features.