Created
January 13, 2012 21:27
-
-
Save averyvery/1608795 to your computer and use it in GitHub Desktop.
Tracking Window Dimensions with GA
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Tracking Window Size</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-1111111-1']); | |
_gaq.push(['_trackPageview']); | |
(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/u/ga_debug.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
(function() { | |
var dimensions = {}; | |
function trackWindowDimensions(){ | |
track('Height', get('Height')); | |
track('Width', get('Width')); | |
track('Total Pixels', dimensions['Height'] * dimensions['Width']); | |
}; | |
function track(name, amount){ | |
_gaq.push(['_trackEvent', 'Window', 'Dimension', name, amount, true]); | |
}; | |
function get(name){ | |
var key = 'inner' + name, | |
object = window, | |
amount; | |
if(!(key in window)){ | |
key = 'client' + name; | |
object = document.documentElement || document.body; | |
} | |
amount = object[key]; | |
return dimensions[name] = amount; | |
}; | |
trackWindowDimensions(); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment