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?
- How do you minimize DNS requests when Google advises you to copy their tracking code, linking to an external-hosted Javascript file?
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 performance of your pages won’t be impacted, with the possible exception of the very first page-load after you have added the tracking code. This first pageview calls the JavaScript on Google’s servers, which may take slightly longer than a regular page load. Subsequent pageviews will use cached data and will not be affected.” – Google’s Official Statement
Google Analytics requires inserting Javascript code into pages and posts on your site. While you can alter your header.php file by hand, the code will disappear when you update your theme. This can catch you by surprise.
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
Load Time: 30 milliseconds
Active installs: Fewer than 10,000
Zip file size: 31k
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.
Reference: websiteoptimization.com
Since we bleed speed, we say, “Load it in the footer.” This may eliminate PageSpeed render-blocking Javascript and above-the-fold content errors, too. A small bonus.
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.
Google Analytics uses Javascript in the tracking code. It also requests a transparent GIF image. This is a 35-byte, 1×1-pixel, transparent image file. It’s referred to as a tracking beacon. And a cookie is also placed on the visitor’s browser cache. Then Google Analytics knows when the visitor returns and becomes a statistical “repeat visitor.” But, what happens if people have cookies turned off? We know it isn’t counted. Surely it messes things up for Google.
Note: Piwik is an open-source (free and fully customizable) analytics tool that doesn’t use cookies. No problem tracking people who turn off cookies.
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.”
How much time will Google Analytics cost mobile users in delays? Let’s compare other common WordPress components: The Google Analytics code delay is as long as loading Javascript. It can be more than loading Google Fonts. It’s like loading Font Awesome. Even emojis are in the same class of deadwood. Do we strip those WordPress non-features? Yes! Whenever possible. So not adding Google Analytics for us is a serious consideration. Even with normal 100 to 200 milliseconds load times. On a 1-second mobile site, that’s a 10- to 20-percent delay for a first-time visitor.
AN ALTERNATIVE: HOST LOCALLY
Google’s advice is to avoid local hosting of the JavaScript file. Why? They claim it ensures you get access to new features and product updates. But that is a suspicious, self-serving dodge. We suspect they’re being sneaky again – and gathering data for their own purposes.
To avoid the extra overhead of off-server resources (DNS lookup and Time to First Byte), you can localize your JavaScripts on your server. This is 13 percent faster than a trip to Google’s remote server.
Speed up sites with two simple changes: 1) Move your analytics code to the bottom, and 2) localize the JavaScript file.
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)
Load Time: 20 milliseconds
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.
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).
“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.
★★★★★
WP CounterLoad Time: 20 milliseconds
Active installs: 2,000+
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.
Great article offsite about how browser ad blockers affect Google Analytics numbers. There’s a strong downward trend in the measurable proportion of visitors.
Another excellent offsite link: https://plausible.io/blog/remove-google-analytics
You can get free metrics from Cpanel on your host server. This doesn’t slow down your website. A good off-site article about how to do this: https://www.hostpapa.com/knowledgebase/view-website-statistics-cpanel/
Pingdom to San Francisco USA Speed test.
Comparison load times for this page you’re reading:
Super Simple Google Analytics plugin – header
CAOS plugin – footer
Metrics using C-panel (no GA-ID)
Speed savings: 334 milliseconds per page.
OFFSITE ARTICLE: Lightweight alternatives to Google Analytics
READER’S COMMENTS
I just wanted to drop in and tell you that I found this article extremely interesting and helpful.
I love Googling. I don’t love Google’s lack of respect for our privacy. And I hate Google Analytics (GA).
I find GA super confusing. Now, after reading your perspective on it, I realize that I was only trying to use it, because I was “supposed” to — and I probably don’t even need it.
You have saved me hours of further angst.
So thank you for taking the time to write this article. It was valuable to me.
— Janine @ Stitching in Colour
Godspeed-
Steve Teare
performance engineer
December 2024
PagePipe Site Tuning Services for Speed
Instead of band-aid approaches, we drill down to the root cause of your slow site. This is origin optimization. Also known as site tuning. To do this, we analyze site components:
- Hosting
- Theme
- Plugins
- Scripts and third-party services.
- Images and media library.
- We minimize globally loading plugin effects.
Find out more details about Site Tuning – Get Speed!