Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Last active December 21, 2015 03:39
Show Gist options
  • Save tomfuertes/6243659 to your computer and use it in GitHub Desktop.
Save tomfuertes/6243659 to your computer and use it in GitHub Desktop.
Use this snippet to get the max out of your site speed samples
/**
* GOAL: Get the maximum allowed RUM data pushed into GA each day
* Use this formula if you're < 1,000,000 Pageviews / Day
* If you're > 1,000,000, disregard this whole thing as the GA auto samples at your capped 1%
* About Page Speed: https://support.google.com/analytics/answer/1205784?hl=en
* About _setSiteSpeedSampleRate: https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration#_gat.GA_Tracker_._setSiteSpeedSampleRate
*/
var AVERAGE_DAILY_PAGEVIEWS = 100000; // Replace with your Average Daily Pageviews from Google Analytics
// needs to be pushed before _trackPageview
_gaq.push(['_setSiteSpeedSampleRate',
AVERAGE_DAILY_PAGEVIEWS < 10000 ?
100 : parseInt(((10000 / AVERAGE_DAILY_PAGEVIEWS) * 100), 10) // PUSH IT TO THE LIMIT
]);
/**
* GOAL: Get the maximum allowed RUM data pushed into GA each day
* Use this formula if you're < 1,000,000 Pageviews / Day
* If you're > 1,000,000, disregard this whole thing as the GA auto samples at your capped 1%
* About Page Speed: https://support.google.com/analytics/answer/1205784?hl=en
* About siteSpeedSampleRate: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#siteSpeedSampleRate
*/
var AVERAGE_DAILY_PAGEVIEWS = 100000; // Replace with your Average Daily Pageviews from Google Analytics
ga('create', 'UA-XXXX-Y', {
// siteSpeedSampleRate has to be set in create
'siteSpeedSampleRate': AVERAGE_DAILY_PAGEVIEWS < 10000 ?
100 : parseInt(((10000 / AVERAGE_DAILY_PAGEVIEWS) * 100), 10)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment