Skip to content

Instantly share code, notes, and snippets.

@jsr
Created October 19, 2010 18:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jsr/fd0896b1e84c7b8d4d12 to your computer and use it in GitHub Desktop.
Save jsr/fd0896b1e84c7b8d4d12 to your computer and use it in GitHub Desktop.
How to measure page load time using google analytics custom variables.
<html>
<head>
<script type="text/javascript">
//<![CDATA[
var page_load_start = new Date();
var _gaq = _gaq || [];
window.onload = function() {
var page_load_end = new Date();
var load_time = page_load_end.getTime() - page_load_start.getTime();
load_time = parseInt( load_time / 100 )*100;
_gaq.push(["_setCustomVar",1,'landingPageTime',load_time,2]);
_gaq.push(["_setAccount","UA-xxxxxxxx-y"]);
_gaq.push(["_trackPageview"]);
}
//]]>
</script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
(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);
})();
//]]>
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment