-
-
Save jsr/fd0896b1e84c7b8d4d12 to your computer and use it in GitHub Desktop.
How to measure page load time using google analytics custom variables.
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
<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