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

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 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?

  • 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 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.

    Legacy: ga.js

    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.

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

    Professional: gtag.js

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

    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.js. Why?

    1. Since gtag.js is 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.js is used (without query strings) all over the internet and is therefore widely available from browser cache.
    2. 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 ga.js, analytics.js and 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.

    Daan van den Bergh

    Daan van den Bergh is a carefully seasoned web developer. His methods consist of thinly slicing your website’s beef and serve you with a platter of the best performance carpaccio on a bed of rocket — the only thing he’s more passionate about is food. Hire him at ffwp.dev.

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

        • 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

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