Created
April 9, 2013 12:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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