Skip to content

Instantly share code, notes, and snippets.

@outmost
Created April 9, 2013 12:11
Show Gist options
  • Save outmost/5345202 to your computer and use it in GitHub Desktop.
Save outmost/5345202 to your computer and use it in GitHub Desktop.
Random sampling of page load time using Boomerang - http://lognormal.github.io/boomerang/doc
<script defer type="text/javascript">
//set random variable
var x = Math.floor((Math.random()*100)+1);
//check to see whether user has tracking cookie set
if (document.cookie.search(/(^|;)perfTrack=/) > -1) {
//if tracking cookie has been set, create alert with page load time
BOOMR.subscribe('before_beacon', function(o) {
alert("hello again, your page loaded in " + o.t_done + "ms");
});
}
// if no tracking cookie exists, check to see whether random variable falls within set range (this example checks 10%)
else if (x >= 30 && x <= 39) {
// set a new cookie to track further page views
document.cookie = "perfTrack=true;max-age=" + 60 ; // 60 seconds to a minute, * 60 minutes to an hour, * 24 hours to a day, * 365 days.
// create alert with page load time
BOOMR.subscribe('before_beacon', function(o) {
alert("tracking initiated, your page loaded in " + o.t_done + "ms");
});
}
// if no tracking cookie exists and variable is outside sample range, do nothing
else {
alert("no tracking " + x);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment