Support » Plugin: CAOS | Host Google Analytics Locally » Plz Explain analytics.js/ga.js/gtag.js

  • Anonymous User 14978628


    Hi, in the options it says you can use ga.js/gtag.js instead of analytics.js.

    Can you explain what the differences are between these two sets? Does ga.js/gtag.js contain less features? Is it more lightweight?

    Just wondering what the benefits/downsides are of switching between these? Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Daan van den Bergh


    Hi @martychc23,

    Good question, I should actually write something about that. But for now, I’ll explain it to you in short:

    – ga.js is the old version, it does not support ecommerce features, for example.
    – analytics.js is the new(er) version of Google Analytics, it does support ecommerce and other features.
    – gtag.js is Google’s Universal Tag, it can be used with other services (such as Tag Manager) as well. This tag will connect to your Google Account, and load all services connected to your account.

    So, in short: if you use different Google Services, gtag.js. If you only use Google Analytics, use analytics.js. If you don’t want e-commerce features, use ga.js.

    Thread Starter Anonymous User 14978628


    Thanks for the info. I did look this up but was rather confused by what i found.

    What i did take away from my reading was that gtag.js was a newer version of analytics.js and so might be better using that.

    I tried changing to gtag.js but still saw analytics.js loading in developer tools. Should i be seeing gtag.js?

    This was the official info i found, but it didn’t really mean much to me:

    analytics.js uses (1) trackers to send data to Google Analytics and (2) hit types to specify the types of the data.

    Unlike analytics.js, gtag.js doesn’t use trackers to send data to Google Analytics. It sends data to Google Analytics properties identified by their IDs set by the config command. The event names supplied to gtag.js specify the types of data being sent to Google Analytics.


    Just found this which suggests analytics is best to use. This i’ll stick with that:

    The other thing to be aware of about gtag is it’s not really an analytics.js replacement, it’s a wrapper library on top of analytics.js (and others), meaning the gtag library still needs to load analytics.js, and it needs to convert all relevant gtag commands to analytics.js commands and run them.

    As of right now, gtag is 54.5K and analytics.js is 33.7K, and since gtag will also load analytics.js, it’s 262% more code for less functionality. There’s also the problem that gtag is site-specific (because you add your tracking ID as a query string), so it’s unlikely your users will have it cached; analytics.js on the other hand is used all over the web, so it’s very likely to already be in your visitors cache when they load your site.

    So, for all these reasons, I don’t plan to switch to gtag as it’ll just end up making my site take longer to load and consume more of my user’s bandwidth.

    Plugin Author Daan van den Bergh


    Jep, gtag.js is newer, but it still loads analytics.js (the external request). You could see it as a layer over the ‘old’ analytics.js, providing a newer (not necessarily better, just asynchronous) way of collecting data.

    If you want my opinion, if you only use Analytics, just set CAOS to use analytics.js.

    Plugin Author Daan van den Bergh


    Thanks for providing all this information. I’ll use it in my article, cause I think many people (including myself! :P) are confused about this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Plz Explain analytics.js/ga.js/gtag.js’ is closed to new replies.