views:

2721

answers:

13

To what extent does Google Analytics impact performance?

I'm looking for the following:

  • Benchmarks (including response times/pageload times et al)
  • Links or results to similar benchmarks

One (possible) method of testing Google Analytics (GA) on your site:

  1. Serve ga.js (the Google Analytics JavaScript file) from your own server.
  2. Update from Google Daily (test 1) and Weekly (test 2).

I would be interested to see how this reduces the communication between the client webserver and the GA server.

Has anyone conducted any of these tests? If so, can you provide your results? If not, does anyone have a better method for testing the performance hit (or lack thereof) for using GA?

+5  A: 

From my own experience it has adding Google-Analytics has not changed the load times.


According to FireBug it loads in less then a second (648MS avg), and according so some of my other test ~60% - 80% of that time was transferring the data from the server, which of course will vary from user to user.


I don't preticularly think that caching the analytics code locally will change the load times much, for the above reasons.

I use Google-Analytics on more then 40 websites without it ever being the cause of any, even small, slowdown, the most amount of time is spent getting the images which, due to their typical sizes, is understandable.

Unkwntech
+3  A: 

There's no/minimal site overhead on the server side.

The HTML for Google Analytics is three lines of javascript that you place at the bottom of your webpage. It's nothing really, and doesn't consume any more server resource than a copyright notice.

On the client side, the page can take a little bit (up to a couple of seconds) of time to finish displaying a page. However - In my experience, the only bit of the page not loaded is the Google stuff, so users can see your page perfectly fine. You just get the throbber at the top of the page throbbing for a little longer.

(Note: You need to place your google analytics code block at the bottom of any served pages for this to be the case. I don't know what happens if the code block is placed at the top of your HTML)

seanyboy
+5  A: 

You can host the ga.js on your servers with no problems whatsoever, but the idea is that your users will have the ga.js cached from some other site they may have visited. So downloading ga.js, because it's so popular, adds very little overhead in many cases (i.e., it's already been cached).

Plus, DNS lookups do not cost the same in different places due to network topology. Caching behavior would change depending on whether users use other sites that include ga.js or not.

Once the javascript has been loaded, the ga.js does communicate with Google servers, but that is an asynchronous process.

Hope this helps.

Yar
+1  A: 

Nothing noticeable.

The call to Google (including DNS lookup, loading the Javascript if not already cached and the actual tracer calls themselves) should be done by the client's browser in a separate thread to actually loading your page. Certainly the DNS lookup will be done by the underlying system and will not, to my knowledge, count as a lookup within the browser (browsers have a limit on the number of request threads they will use per site).

Beyond that, the browser will load the Google script in parallel along with all other embedded resources, so you will potentially get an extremely slight increase in the time it takes to download everything, in the worst case (we're talking in the order of milliseconds, unnoticable. If the Google script is loaded last by the browser, or you don't have many external resources on your page, or if your page's external resources are cached by the browser, or if Google's script is cached by the browser (extremely likely) then you won't see any difference. It's just absolutely trivial overall, the same effect as sticking an extra tiny picture on your page, roughly speaking.

About the only time it might make a concrete difference is if you have some behaviour that fire on the onLoad event (which waits for external resources to load), and the Google servers are down/slow. The latter is unlikely to happen often, but if this were the case then the onLoad even won't fire until the script is downloaded. You can work around this anyway by using various "when DOM loaded" events, which are generally more responsive as you don't have to wait for your own scripts/images to load this way either.

If you're really that worried about the effects on page load time, then have a look a the "Net speed" section of Firebug, which will quantify this and draw you a pretty graph. I would encourage you to do this for yourself anyway as even if other people give you the figures and benchmarks you request, it will be completely different for your own site.

Andrzej Doyle
Are you sure that "the browser will load the Google script in parallel along with all other embedded resources"? Tried it?
Arne Evertsson
Page rendering pauses on <script> tag detection, nothing is done in parallel, for example, try something like: <script>while(true){}</script><p><img src="/picture.jpg" /></p> and see if the picture shows after your cache has cleared
jakemcgraw
+2  A: 

There are some great slides by Steve Souders (client-side performance expert) about:

  • Different techniques to load external JavaScript files in parallel
  • their effect on loading time and page rendering
  • what kind of "in progress" indicators the browser displays (e.g. 'loading' in the status bar, hourglass mouse cursor).
orip
+2  A: 

Loading any extra javascript to your page is going to increase the download time from the client's perspective. You can ameliorate this by loading it at the bottom of your page so that your page is rendered even if GA is not loaded. I would avoid caching because you would lose the advantage of the client cache for your page. If the client has it cached from some other page, your page's request will be filled from the client itself. If you change it to load from your site, it will require a download even if the client already has the code (which is likely). Adding a task to your software processes to avoid loading the file from Google seems unwarranted for what may be an unnecessary optimization. It would be hard to test this since it would always serve up faster locally, but what really matters is how fast it works for your customers. If you decide to evaluate keeping it locally, make sure you test it from your home internet connection --- not the machine sitting next to the server in your rack.

tvanfosson
+13  A: 

The common way of implementing GA is putting the JS at the bottom of the page. This means the rest of your DOM can load before the browser even thinks about accessing Google. This should keep things snappy.

I wouldn't recommend caching the JS file.

  • It might already be in the users cache (quite a high probability if they use the internet a lot) .
  • Co-hosting it would it means your server will needlessly take on a lot more requests, potentially slowing down your core systems.
  • Browsers are limited on how many requests they'll push to one server at a time so sticking the GA JS on your domain will probably mean it takes longer for it to get processed.
  • Google's servers are better than yours.
Oli
+1 for the obvious, yet understated fact that google has better servers.
Unkwntech
Google may have better servers, but they don't deliver the file gzipped if possible; 22k isn't a huge file, it's large enough to benefit from gzipping, especially being plain text (it cuts it down to 10k on my server.).
Ross
+5  A: 

I haven't done any fancy automated testing or programmatic number crunching, but using good old Firefox with the Firebug plugin and a pair of JS variables to tell the time difference before and after all GA code is executed, here is what I found.

Two things are downloaded:

  1. ga.js is the JavaScript file containing the code. This is 9kb, so the initial download is negligible and the filename isn't dynamic so it's cached after the first request.

  2. a 35 byte gif file with a dynamic url (via query string args), so this is requested every time. 35 bytes is a negligible download as well (firebug says it took me 70ms to dl it).

As far as execution time, my first request with a clean browser cache was an average of about 330ms each time and subsequent requests were between 35 and 130 ms.

Rich
A: 

I don't think this is what your looking for but what are you worried about performance for?

If its your server... then there's obviously no impact as it resides on Google servers.

If its your users that your worried about then there is no impact either. As long as you place it just above the body tag then your users will not receive anything slower than they would before... the script is loaded last and has no affect on the appearance to the user. So there essentially not waiting on anything and even continue to browse through the page without noticing that its still loading.

youdontmeanmuch
+2  A: 

Use FireBug and YSlow to check for yourself. What you will discover however is that GA is about 9KB in size (which is actually quite substantially for what it does) and that it also sometimes does NOT load very fast (for what reasons I don't know, I think it might be the servers "choking" sometimes)

We removed it due to performance issues on our Ajax Samples, but then again for us being ultra fast and responsive was priority 1, 2 and 3

Thomas Hansen
Thomas, do you have any numbers as to what improvements did you get after removing the GA code. In terms of response times, in %ages or values itself?
Mohit Nanda
I love how everybody's so smart (me included) but the empirics of the situation are DIFFERENT (aren't they always?). Thanks for y our answer, fascinating.
Yar
+1  A: 

Well, I have have searched, researched and expored extensively on net. But I have not found any statistical data that claims either in favour or against of the premise.

However, this excerpt from http://www.ga-experts.com claims that its a Myth that GA slows down your website.

Err, well okay, maybe slightly, but we’re talking about milliseconds. GA works by page tagging, and any time you add more content to a web page, it will increase loading times. However if you follow best practice (adding the tag before the </body> tag) then your page will load first. Also, bear in mind that any page tag based web analytics package (which is the majority) will work the same way

From the answers above and all other sources, what I feel is that whatever slowdown it causes in not percieved by the user as the Script is included at the bottom of the page. But if we talk of complete page-loads we might say that it slows down the page-load time.

Please post in more info if you have and DATA if you have any.

Mohit Nanda
It's a bit odd that articles like the one above often only test while the Google Analytics servers are running fine. Things may be more troublesome when those servers are under heavy load. And if the servers are experiencing problems, many reloads of impatient users may make things even worse.
Arjan
+3  A: 

The traditional instructions from Google on how to include ga.js use document.write(). So, even if a browser would somehow asynchronously load external JavaScript libraries until some code is actually to be executed, the document.write() would still block the page loading. The later asynchronous instructions do not use document.write() directly, but maybe insertBefore also blocks page loading?

However, Google sets the cache's max-age to 86,400 seconds (being 1 day, and even set to be public, so also applicable to proxies). So, as many sites load the very same Google script, the JavaScript will often be fetched from the cache. Still, even when ga.js is cached, simply clicking the reload button will often make a browser ask Google about any changes. And then, just like when ga.js was not cached yet, the browser has to await the response before continuing:

GET /ga.js HTTP/1.1  
Host: www.google-analytics.com  
...  
If-Modified-Since: Mon, 22 Jun 2009 20:00:33 GMT  
Cache-Control: max-age=0  

HTTP/1.x 304 Not Modified  
Last-Modified: Mon, 22 Jun 2009 20:00:33 GMT  
Date: Sun, 26 Jul 2009 12:08:27 GMT  
Cache-Control: max-age=604800, public  
Server: Golfe  

Note that many users click reload for news sites, forums and blogs they already have open in a browser window, making many browsers block until a response from Google is received. How often do you reload the SO home page? When Google Analytics response is slow, then such users will notice right away. (There are many solutions published on the net to asynchronously load the ga.js script, especially useful for these kind of sites, but maybe no longer better than Google's updated instructions.)

Once the JavaScript has loaded and executed, the actual loading of the web bug (the tracking image) should be asynchronous. So, the loading of the tracking image should not block anything else, unless the page uses body.onload(). In this case, if the web bug fails to load promptly then clicking reload actually makes things worse because clicking reload will also make the browser request the script again, with the If-Modified-Since described above. Before the reload the browser was only awaiting the web bug, while after clicking reload it also needs the response for the ga.js script.

So, sites using Google Analytics should not use body.onload(). Instead, one should use something like jQuery's $(document).ready() or MooTools' domready event.

See also Google's Functional Overview, explaining How Does Google Analytics Collect Data?, including How the Tracking Code Works. (This also makes it official that Google collects the contents of first-party cookies. That is: the cookies from the site you're visiting.)


Update: in December 2009, Google has released an asynchronous version. The above should tell everyone to upgrade just to be sure, though upgrading does not solve everything.

Arjan
A: 

The question was will Google Analytics cause your site to slow down and the answer is yes. Right now at the time of writing this Google-Analytics.com is not working so sites that have that in their pages won't load the pages so yes, it can slow down and cause your site to not even load. It's uncommon for google-analytics.com to be down this long which right now has been over 10 minutes, but it just shows that it is possible.

Dating Solutions