How does Google Analytics affect mobile speed?

12 minute read
PagePipe specializes in mobile WordPress speed strategy for web businesses using free plugins and themes.

Save the Internet from WordPress speed abuse.

Updated: June 2017
PagePipe Home-page Pingdom speed results. Using cruddy GoDaddy shared, magnetic hosting and old PHPv5.4. You can build-in speed, too.

Google Analytic code causes your site to fail two speed tests. And they’re invented by the web-demigod Google. Yes. Contradictions in their very own self-acclaimed PageSpeed test:

  1. How do you leverage browser cache when Google’s very own Analytics.js has it’s expiry time set to 2 hours?
  2. 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 330 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

Our “Google Analytics for Mobile Speed” eBook is 2,279 words.
Signup below to download the PDF for free.

Enter your email address to download Google Analytics for Mobile Speed – PDF.

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

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.

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.

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?

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? 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 return users. 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.

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)
5,000+ active installs, 7k download
(formerly called Host Analytics JS Local plugin)

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.

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.

Time is better spent improving your website.

Our rule of thumb: Google Analytics adds 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.

Godspeed—

Steve Teare
performance engineer

Serious Mobile WordPress Speed Strategy for Business

What others think of us:


"Hi Steve, Thank you so much for that insightful speed review! I appreciate the time you took to explain the issue of the website I'm working on. I'll be looking into some of the recommendations you have and advice that you have given." skiveworks.com, Singapore

by - Jaaze Lim