• Skip to primary navigation
  • Skip to main content
  • Skip to footer

WPJohnny

WordPress Performance Guides and Reviews

  • Start a WordPress site
  • Hosting
  • Themes
  • Plugins
  • Blogging
  • Marketing

Fastest ways to load Google Analytics JS on WordPress

WordPress hosting Apr 5, 2018 by Johnny 16 Comments

Load Google Analytics faster on WordPress!

If you’ve ever been addicted to speed-testing your site on Pingdom/GTmetrix, then you know exactly what I’m talking about. That GA JS request lags your site costing you an extra 100ms-2seconds of load time. Below are my favorite methods to prevent the Google Analytics JS from slowing down your site.

Here’s how to speed up that annoying Google Analytics javascript on WordPress:

 

Why Speed Up GA Script Load?

How important is it to speed up the GA script? Most of us are only thinking about it because we saw it on a page speed test and want faster times and higher scores. The reality is…that file is probably on every browser and heavily cached. Your device might load it but it probably doesn’t call it every time. Nonetheless, you’re welcome to discover your own tactics of speeding it up for function or aesthetic purposes. Enjoy!

 

METHOD #1 – Using a cache plugin (fastest)

  • This is definitely the fastest way. Simply load it with your cache plugin which may or may not combine it with all your other JS scripts, depending on what settings are available.
  • Not all cache plugins handle GA caching. I use Swift Performance Lite. (Here’s the premium version with more features). Just make sure you don’t forget to re-enable GA if you decide to disable caching.

 

METHOD #2 – Using a GA plugin (2nd fastest)

  • Complete Analytics Optimization Suite (CAOS) – nice plugin that saves the latest GA.js file on your server and loads it locally. The file is synchronized with the latest GA from Google servers and updated periodically. You save one request and speed up page load times. Works well, very easy-to-use and lean.

 

METHOD #3 – Locally-loaded GA script (2nd fastest)

  • I don’t recommend this since it’s a pain in the ass to setup and requires a lot of technical knowledge to call the script manually from your theme and also to figure out a way to keep the file updated using cron. Should there be any mistakes, you might miss out on some of the proper GA tracking.
  • You can search Google for various methods of accomplishing this. Again, I don’t recommend it.

 

METHOD #4 – Using your theme (regular speed, safest)

  • This is the safest and lean way to load Google Analytics, since it isn’t reliant on caching or other plugins. Most WordPress themes have a place where you can enter your scripts and even choose header or footer position. The speed is the same as the default way since you’re loading the full script which makes all the usual requests (2?). I prefer to load GA in the footer instead of the the header.
  • For those without a place to load scripts in your theme, simply use one of the Google Analytics plugins mentioned above.
  • Another option if you don’t want CAOS plugin is to the GA Google Analytics plugin. It’s also lean.

 

METHOD #5 – Bloated GA plugin (slow)

  • This method is only listed for comparison purposes. I hate the big bloated plugins that show you fancy charts from your WordPress dashboard. I also don’t recommend to select all the unnecessary options like Display Advertising, etc and etc. 99% of you don’t need them.

 

Other methods of loading GA Analytics

  • GA Lite using JSdelivr – smaller, lightweight, locally-loaded or CDN-loaded cacheable GA script. More explanation about it here as well.

Share this post:

Share on FacebookShare on X (Twitter)Share on LinkedInShare on WhatsAppShare on EmailShare on SMS

Read all my posts on WordPress hosting

About Johnny

Right on the edge of WordPress development! 10+ years of WordPress design, development, hosting, speed optimization, product advisor, marketing, monetization. I do all that.

More WordPress Guides

How to Solve Problems

Linode has the best cloud manager UI

Which is the fastest WordPress theme?

How Unique Should Your Logo Design Be?

The WordPress Open-Source Conundrum

Removing WordPress user registration spam

Reader Interactions

16 Comments

  1. Regev

    October 21, 2019 at 1:42 pm

    Hey Johnny,
    Google Analytics has been giving me nightmares the past few weeks. Completely messed up – errors and everything inside their site. I thought of just getting rid of it, since I barely use it (just to see the *overall* traffic every once in a while) – I use Google Search Console to see how much search traffic, new external links, which keywords and what SERP placements, etc and improve accordingly. Do you still use GA? what are your thoughts?

    Reply
    • Johnny

      October 21, 2019 at 5:33 pm

      I use GA without any issues and do love the convenience. But that’s because I have real traffic on my sites and a ton of it from different places. Do I really really need it? Probably not, could run my business well even without. I have a good pulse on things and can guess my traffic but I think people should use it at least until they’ve created 1 successful site.

      Reply
      • Reg

        October 21, 2019 at 11:02 pm

        What do you do with GA data though except for seeing how much traffic you get? Improving UX within the site to reduce bounce rates, etc?

        Reply
        • Johnny

          October 22, 2019 at 2:27 pm

          Hahaha, thanks to your good question…I made a whole post just for you. 🙂
          https://wpjohnny.com/metrics-track-google-analytics/

          Reply
          • Regev

            October 22, 2019 at 2:52 pm

            I LOVE YOU JOHNNY!!!

          • Johnny

            October 22, 2019 at 5:11 pm

            Hahaha, I love you too man!

  2. John @ S4

    May 9, 2020 at 10:41 am

    We use CAOS a lot. It’s great and never fails, but seems to be becoming less lean and simple with every new release adding a little something extra.

    Reply
    • Johnny

      May 9, 2020 at 10:44 am

      What’s not lean about it? CAOS mainly locally loads your GA, which makes most of the difference. Whether extra 1kb or so for the GA script, I think is not a big deal.

      Reply
      • John @ S4

        May 10, 2020 at 10:29 am

        Don’t get me wrong I still love CAOS and use it everywhere.

        I just want very little, maybe less than most people, from GA and therefore from a GA plugin, I chose CAOS originally because it did so little, but now it has stealth mode lite, google optimize integration, enhanced link attribution, and big adverts asking me to upgrade to super stealth mode.

        I’m sure it’s all good stuff, I just personally preferred it as simple as simple could be.

        Reply
        • Johnny

          May 10, 2020 at 10:33 am

          Hmmm….then try Flying Analytics by Gijo, maybe that’s more of your type.

          Reply
          • John @ S4

            May 11, 2020 at 11:35 am

            Thanks, never tried it, but I’ll take a look.

    • Martin

      August 12, 2020 at 10:16 am

      The plugin affected my analytics in the past e.g. broken bounce rate. I had to switch to manual implementation.

      Reply
  3. Martin

    August 12, 2020 at 10:19 am

    METHOD #3 – Locally-loaded GA script (2nd fastest)==> Try this guide and you will change your mind https://themefreak.net/blog/how-to-cache-google-analytics-code/ (I jumped set up htaccess since LS Cache does it)

    Reply
    • Johnny

      August 12, 2020 at 10:44 am

      Thanks for sharing. I prefer to rely on a plugin to do it but yes. That method works!

      Reply
      • Martin

        August 12, 2020 at 11:25 am

        The same plugin broke my GA script e.g broken bounce rate, hence I switched to this method.

        Reply
  4. Ryan

    December 1, 2020 at 11:19 am

    Any thoughts on Site Kit from Google?

    Reply

Leave a Reply Cancel reply

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

Footer

More links

  • Gadget reviews
  • Try my free WPJ plugins
  • Join the WPJ FB Group
  • WPJ YouTube & newsletter
  • Become a WPJ Affiliate

Popular Reviews

  • Best WordPress Hosting
  • Best WordPress Themes
  • Best WordPress Plugins
  • Best WordPress Cache Plugins

Services

  • Speed optimization
  • Speed optimization courses
  • WordPress hosting
  • Hire me or other experts
  • Client login

About Johnny

10+ years of WordPress design, development, hosting, speed optimization, marketing.
Contact me.

newsletter block

Copyright 2025 | WordPress guides by Johnny Nguyen

Click to Copy