Use _setSiteSpeedSampleRate() to Improve Your Google Site Speed Performance

Over the last month or so I have been trying to focus on improving the overall performance of Grownupgeek.com.  Knowing that Google is already, or someday will be using site speed performance as a ranking metric and knowing that nobody likes a slow website, it seems like a smart thing to focus on.

I’ve already done the standard things to make the site load faster:

  • Installed a PHP Accelerator
  • fine-tuned Drupal Caching with the Boost module
  • lightened the pages by removed a few unnecessary visual elements like buttons for links (trade off between pretty or faster)
  • Replaced images with losslessly compressed PNG or JPG files, particularly on high-traffic pages
  • Enabled Mod_Deflate on the server to compress HTML, CSS, and JS
  • Fixed a long-time DNS issue that measurably reduced DNS lookups to the server and memory usage
  • Removed Kontera from many high traffic pages as it was one of the biggest speed-killers

All of these changes made an overall impact on my PageSpeed ratings taking most pages from the mid to high 80’s up to the mid 90’s but I was not seeing the improvements in my Analytics Site Speed overview or my Webmaster Tools that I expected to see.  The Google Webmaster Tools Site Speed data is captured from website visitors that have installed the Google Toolbar and have enabled the PageRank feature so I have no control over that, but the Google Analytics stats are collected via the Analytics code, so there is at least one thing we can do to improve that metric.

The Google Analytics tracking code collects site speed performance on approximately 1% of page loads by default.  The problem with such a relatively small data sample is that it only takes a few visitors located in Jerkoffistan connecting on a 2400BPS modem to drag down and skew the entire average.  This can be confirmed by looking at your daily Analytics Site Speed Timings report by region, then sort it by Avg. Page Load Time.  I was finding many pages with load times of 100 – 300 seconds based on ONE Page Load Sample, usually from third-world countries.  It doesn’t really matter where these Page Speed skewing visitors are located – what matters is that it only takes a few of these single data points to increase your entire overall Site Speed Page Average.

Since it is not possible to control the location or connect-speed of your visitors, about the only other thing you can do is increase the number of page speed samples that are collected by Google Analytics – hopefully a larger data sample will give a better representation of your actual site speed.

How to get more Page Load Samples:

Google Analytics has many customizable settings variables.  One variable, _setSiteSpeedSampleRate() allows you to define a new sample set size for Site Speed data collection other than the default of 1% page views.  The syntax for _setSiteSpeedSampleRate() is:

_gaq.push(['_setSiteSpeedSampleRate', X]);

Where X = your desired Site Speed sample percentage.  A value of 10 would yield a sample rate of 10% of page views.

Simply place the _gaq.push(['_setSiteSpeedSampleRate', X]); in your existing Google Analytics code – being careful to place it BEFORE the existing _trackPageview() in your code.

Example of the _setSiteSpeedSampleRate for a 10% sampling rate:
var _gaq = _gaq || [];_gaq.push(["_setAccount", "UA-696969-1"]);_gaq.push(['_setSiteSpeedSampleRate',10]);
_gaq.push(["_trackPageview"]);(function() {var ga = document.createElement("script");
ga.type = "text/javascript";ga.async = true;ga.src = ("https:" == document.location.protocol ?
"https://ssl" : "http://www") + ".google-analytics.com/ga.js";var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(ga, s);})();

Be careful to include a ; (semicolon) immediately after _gaq.push(['_setSiteSpeedSampleRate',10]) and remember to put _gaq.push(['_setSiteSpeedSampleRate',10]); before _gaq.push(["_trackPageview"]);

If you are using the Drupal Google Analytics module this can easily be added in the Advanced Settings, in the custom javascript section.  Just paste in the _gaq.push([‘_setSiteSpeedSampleRate’, 10]);  (replace the number 10 with your desired sample rate %) into the “Code Snippet (Before)” field.  Be sure to include the semicolon.

After placing the updated Analytics code the increased sample rate takes effect almost immediately and you should see more page samples in Google Analytics in an hour or less.  In my case this has taken the number of daily page samples from 75 – 100 (max) per day up to several hundred per day, and has resulted in lower daily average site speeds reported in Google Analytics.

I do not know if Google uses this particular data point to determine search rankings, but even if it has no bearing on your search ranking, having a larger data set will help to give you a more realistic picture of your website performance and hopefully a little warm-fuzzy.

One thought on “Use _setSiteSpeedSampleRate() to Improve Your Google Site Speed Performance

Leave a Reply

Your email address will not be published.