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?

  • The Wait is Over.

    Get the Newsletter you've always wanted, now!

    Sign up to receive monthly, Special Offers & Free Optimization Tips for WordPress.

    Privacy Policy

    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)

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

    For CAOS users I still recommend to use analytics.js unless you have reasons to use gtag.js.

    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.

    Summary

    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.

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

    1. CAOS is great wp plugin but google Tag manager is used as centralized tool for all the tracking. In my case, I have already use Tag manager. and also installed CAOS plugin then i got google analatic JS error. (for testing purpose i have done install CAOS)

      So i would like to invite you to create new plugin for google tag manager like CAOS

      Thanks

    2. Thank you so much for the article. It was very useful and helped me with some questions I had. Greetings from Venezuela.

    3. Hi

      It would be great if you add the support for AMP pages also in CAOS with other tracking features. Because for AMP pages there are very limited resources.

      Thank you

    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.