What’s the Difference Between analytics.js, gtag.js & ga.js?

Besides 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 ga.js, analytics.js and 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?

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 ga.js, analytics.js and 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.

ga.js (legacy)

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 ga.js.


Warning: Universal Analytics (V3) is deprecated and will be discontinued as of July 1, 2023.

This is the recommended file to go for, unless you are planning to migrate to Google Analytics V4 or use other Google services.

Athough this library is much lighter in weight (46 KB) compared to gtag.js — which (depending on your settings) can reach >100KB — I can no longer recommend using this library, since it will be discontinued as of July 1, 2023.

For those of you that are planning to migrate to Google Analytics V4, I’d recommend switching to gtag.js (V3) and setup dual tracking. CAOS allows you to set this up easily.

gtag.js (v3/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 has only recently been lifted out of beta status (!) If you use CAOS Pro in Stealth Mode this might cause issues.

I strongly suggest you run UA (v3) and GA4 in parallel for a while — using gtag.js — before switching to the V4 API. This way you can compare data, and make sure that GA4 is tracking your site accurately.

CAOS allows you to easily setup Dual Tracking, by simply providing a UA- tracking ID and G- measurement ID.


In this post I’ve discussed the differences between ga.js, analytics.js and gtag.js. I’ve given several arguments to help you decide and recommended the usage of either analytics.js or gtag.js — also for CAOS users — for two reasons: performance and availability of features.

❤️ it? Share it!

21 thoughts on “What’s the Difference Between analytics.js, gtag.js & ga.js?”

    1. Hi Freddy,

      CAOS isn’t a Google Tag Manager plugin, it’s a Google Analytics plugin. You can’t use CAOS to add GTM tag to your site. You probably should keep your current setup.

      1. Hi,

        First, thanks a lot for your work and all the knowledge you give.

        About GTM, you can, if you need, add Google Analytics through the CAOS plugin but still use GTM to add other tags or inject some more JS (without having to access to the server).

        If you want to send some google analytics event through GTM you can do it without habing add the tag with GTM.
        In the event tag in GTM, you check the “Autorize the replacement …” and you put the UA-XX in the tag ID input.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Shopping Cart
  • Your cart is empty.