Google Analytic code causes your site to fail two speed tests. And the test criteria are invented by the web-demigod Google. Yes. Contradictions in their very own self-acclaimed PageSpeed test:
- How do you leverage browser cache when Google’s very own Analytics.js has it’s expiry time set to 2 hours?
Google Analytics usually adds three HTTP requests. And anywhere from 100 milliseconds to 500 milliseconds load time. It can be slower during peak hours. We’ve seen up to one second. But that’s uncommon. Speed varies in different parts of the globe. That means certain hours are better and some are worse for waiting.
Google Analytics is a freemium web analytics service offered by Google that tracks and reports website traffic. … Google Analytics is now the most widely used web analytics service on the Internet. – Wikipedia
There were times when we built 50k to 70k home pages for speed. Page weight today averages 2 to 3M. We coded lightweight sites by hand in HTML and CSS. Today most site owners use CMS like WordPress to build websites.
Back then, adding Google Analytics added about 31k to the page weight. This, of course, was a horrific detriment to good speed. Today, Google serves a Gzip-compressed version weighing 13k. Much better page weight.
In 2010, Google introduced a third-generation asynchronous tracking code. This helped speed immensely – and in time for the Internet mobile revolution. But, does that mean Google Analytics code has no impact on speed? Or is it significant? It depends.
The more modern alternative is using the Goggle API ID number and copying that into a plugin. This protects your Google Analytics code from being overwritten by updates. A safer approach.
Super Simple Google Analytics plugin
10,000+ active installs, 31k compressed download
But not all Google Analytics plugins are equal. Some cause server overhead that slows down your site indirectly. The page drag from these database-intensive plugins aren’t worth it.
If you need to look at Google Analytics statistics every single day or more than once per week, ask yourself: Why? What is so important about seeing the numbers and metrics so often? Are you obsessed? Spend time writing relevant content. Bring more qualified visitors to your site.
Header or Footer? Small decisions.
There’s a silly debate whether to place Google tracking code in the WordPress header or footer. Those obsessed with statistics say, “Put it in the header.” Those obsessed with speed say, “Place it in the footer.” Even Google’s different departments can’t agree where’s the best placement.
It’s reported pages load 100 milliseconds faster with the Google Analytics code in the footer.
Placing the code higher in the page theoretically decreases bounce rate. It’s claimed to reduce data inaccuracies as much as 5 percent – in some tests by Google Analytics-certified partners. Certified by who? Google partners! No conflict of interest there.
“If Google Analytics tracking code doesn’t load before a visitor leaves or clicks away from the page, the page data won’t show up in Google Analytics.”
Oh, dear. Statistical tragedy.
Pages load so snappy we don’t think users can determine content value that fast. And then navigate to the browser back button. Yes – that would technically be a bounce. But the idea of putting tracking at the top seems a moot point. By putting it at the bottom, you’re effectively lazy loading the tracking code. Lazy loading anything that delays page rendering is a good idea for speed. The slight chance of losing a minutia of visitor data is more than offset in the gain in display speed.
Isn’t the Google Analytics code cached in the browser?
If your Google Analytics code is slowing down your site by more than 1 second, something is wrong. You need to investigate how you’re managing things. On slow-loading pages, a browser status message may say “Waiting for google-analytics.com”. If this happens you’re running an ancient version of Google Analytics tracking code. Time to upgrade.
Which version of the code? OK. We’re being cynical. Maybe it is. Maybe it isn’t. It doesn’t make a difference if it’s cached by the browser. For some reason, Google Analytics interrogates the Google remote server anyway. What’s it looking for? That new version you don’t have cached? Or just reporting in for Google’s own nefarious snoopy purposes? We’ll never know. From what we’ve seen in tests: The ga.js communicates with Google servers even when ga.js is cached. At least once. Perhaps always.
Now, some *premium* hosts provide server caching. This can benefit Google Analytics code load time. But not always. The best improvement we’ve seen is a 50-millisecond load time. That’s about 6-times faster than normal shared hosting. Is it worth paying extra for that 50 milliseconds? Well, you will pay 10 times more for the hosting. So don’t signup for Google Analytics sake!
Some reports say the Google Analytics files are marked as “no-cache.” Others say they’re cached for 24 hours. The latest news is only 2 hours. We agree – it’s 2-hours from tests we’ve run. That is too short for any value to your return visitors. And online speed tests show that shortness is a failure. The majority of users are first time visitors. At the first visit, Google Analytics code loads at least once. It may not loaded after that (cached). But it’s part of the “first impression speed” for mobile users. It’s not uncommon for first-time visitors being 80 percent of traffic.
“… you can reduce your external HTTP requests to Google from 2 down to 1 and you now have full control over the caching of the file. This means you can utilize your own server’s cache headers.
You have also probably seen the leverage browser caching warning in Google PageSpeed Insights that comes from Google Analytics. This is kind of ironic seeing as this is Google’s own script. The issue is that they set a low 2 hour cache time on their asset … They most likely do this because if for some reason they were to modify something on their end, they want all users to get the changes as fast as possible. However there is a way to get around this, and that is by hosting Google Analytics script on your own server.”
AN ALTERNATIVE: HOST LOCALLY
Coding Jargon: Host the ga.js and __utm.gif file locally and execute the _setLocalServerMode() method.
Wow! That sounds complicated. But there’s a free plugin that does all this magic for you. Now, you can optimize Google Analytics. We’re using this plugin on PagePipe and other sites.
Complete Analytics Optimization Suite (CAOS)
10,000+ active installs
Gzip file size: 7.4k
Retention: 38 percent
[perfectpullquote align=”right” cite=”” link=”” color=”blue” class=”” size=”14px”]Note: When you do the CAOS method, your pages will fail various, odd online tests – not speed tests. The Google Analytics code won’t appear where the test *expects*. Your site’s OK. It’s the test that’s broken. Everything will appear normal in the Google Analytics dashboard and controls.[/perfectpullquote]
This plugin inserts the Analytics tracking code into the header or footer (you choose). It saves the analytics.js file locally. It then keeps it updated daily using scheduled automation.
Whenever you test speed on Google Pagespeed Insights or Pingdom, they’ll tell you to leverage browser cache. That’s because Google set the cache expiry time to 2 hours, it always fails the test. This plugin will get you a higher score on PageSpeed and Pingdom and make your website load faster. (Scores are nice – but saving milliseconds of load time is what really counts). No more roundtrip to download the file from Google’s external server.
Will the CAOS plugin make your website go from a 10-second load to a 1-second load? In Disneyland! Get real. It’s a small speed boost – but it’s worth it.
The Complete Analytics Optimization Suite for WordPress gives you the best of both worlds. This way you can minimize DNS requests, leverage browser cache, track your visitors – and still follow Google’s recommendation to use the latest features and product updates. If you’re using a CDN, you’ll need to use CDN Enabler plugin to host your Analytics-script (local-ga.js) from your CDN.
UPDATE: Let’s take a closer look at a real-world site, PagePipe! Below is a waterfall from WebPagetest.org:
With the CAOS plugin activated – the tracking occupies the space of 1.3 seconds to 1.7 seconds. (The site’s favicon also lazy loads. This happens when placed in the root of your host server – but that’s another topic). A little math and we see that it’s a 500-millisecond delay for Google Analytics to respond. Without Google Analytics, the site would theoretically load in 1.2 seconds. Let’s turn off Google Analytics and the CAOS plugin for a moment. What’s the real difference in seconds?
The page now loads in under 1.1 seconds. We can ignore that lazy-loaded favicon. So Google Analytics adds a repeatable 500 milliseconds to every page. That’s site drag! We’ve seen delays of over a second – but it isn’t repeatable. It’s random. Simply waiting in line.
So now we ask, “What is Google Analytics affect when using the Super Simple Google Analytics plugin?” Here’s the answer:
A 1.8 second load time is the result. Instead of 500 millisecond addition with CAOS plugin, it’s now a 700 milliseconds addition. 200 milliseconds more!
CAOS plugin saves 200 milliseconds. For mobile speed, that’s great. And optional loading in the footer is reported to save an additional 100 milliseconds. That’s 300 millisecond gain of total improvement.
The fastest loading Google Analytics: No Google Analytics at all.
Ask yourself, “Why am I installing Google Analytics?”
Now, some sites need Google Analytics more than others. For example, an ecommerce site. But a typical blog site usually not. And a vanity site, definitely doesn’t. Many site owners install Google Analytics code because everyone else does it. And then they never even look once at the metrics. Ever. All they did was slow things down – without any benefit.
Using too much data to make decisions is worse than having no data. Seeing that 35 people visited on Wednesday last week, do you care about that detail? Whoopee. The data provided by Google Analytics is massive and takes time to learn how to use. We drown ourselves in data and just sink deeper into the quagmire.
Google Analytics statistical data gathering is never 100% accurate. The data extracted is still subject to human evaluation, spam, and error of judgment. It’s like reading tea leaves, fortune cookies, or tarot cards. You *interpret* what your mind wants you to see.
There is no science to SEO (or even UX) since no one can prove the outcome was a direct result of the method. It’s professional guesswork based on experience and a moving target. Page One in Dallas does not ensure Page One in Seattle.
Data can twist your perception.
Because everyone else uses Google Analytics, should you jump off the cliff, too? Would you install a plugin because:
- It’s very easy to use.
- Everyone else uses it, so it must be the best.
- It’s free. Who can argue with free?
Are these the right reasons for choosing an analytics tool?
What would your mother say about peer pressure?
It’s actually very difficult to get real insight. 25 to 33 percent of your traffic is non-human (bots). With Google Analytics, spam-bots get recorded as a real live visitor. Most ad-blockers and tracking blockers also block Google Analytics. Those things affect your numbers.
Google Analytics can be a time waster.
If we can’t define what “the best” or even “good enough” means, how can we say Google Analytics is the best solution?
Google Analytics is good for a baseline in projects. It helps ecommerce know what products customers searched for. And what they viewed when they got there. Most people don’t know how to read the data. Less than 1 percent of website owners know how to use Google Analytics. Let alone how to glean helpful information from all that data.
Google Analytics data won’t help you write better thought provoking content. Instead, it may twist your thinking to chasing the herd.
Most (major) web hosts give you the ability to read the server logs. There you get the basic traffic info you’d get with Google Analytics. And the best part is that it requires no script to load: it works on the server, not the client side. Those will show key performance indicators (such as bounce rate, page views, time on site).
Tip: We use a popular-post plugin to build a database of what is trending on our site.
“Yes – looking at analytics data over time is helpful. But do you really need to know if you had 100 or 200 visitors today? … Does any of that data actually do anything for you in the moment? Years of experience have taught me that it doesn’t.”
Author: Colin Newcomer
Time is better spent improving your website.
Our rule of thumb: Google Analytics adds at least 100 milliseconds to the first page view of your site. That page is most critical for mobile users. That can be 10 percent of wasted load time. Whenever possible, delete Google Analytics. Use either a plugin counter or Cpanel or server web statistics as a substitute.
We’re not against using Google Analytics if you need it. Read the data collected. Use it to make your site better. If you do that then keep Google Analytics on your site. If you’re never going to look at the data, speed up your site by removing this unneeded code from loading.
It’s claimed Google monitored bounce rate (via GA) affects SEO. We don’t believe it. We really don’t need more data. We get numbers from a plugin and server stats. They are fine and with no speed delays.
Active installs: 2,000+
Zip archive: 5.2k
Last updated: 1 year ago
WP Counter is a lightweight, simple site visitor counter. See unique site visitor status in different date ranges. (Today, Yesterday, Current Week, Current Month). We’ve been using this plugin for months to see if it correlated with Google Analytics. Frankly, nothing correlates to Google Analytics exactly – but it was close enough.
For tracking article popularity, we use WP Popular Posts plugin’s dashboard settings to view stats on all of our posts:
WordPress Popular Posts
Active installs: 300,000+
Zip archive: 122k
Last updated: 3 weeks ago
We’ve written an article about choosing the fastest popular post plugins: How do I get users to read more of my content?
Mobile WordPress Speed – without coding!