Created
October 18, 2012 09:03
-
-
Save WolfieZero/3910572 to your computer and use it in GitHub Desktop.
Track browser size in Google Analytics (not just screen size)
This file contains hidden or 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
/** | |
* What this script will do is add a new tracking metric to work out the actual | |
* size of a browser window (where as Google only tracks screen size). Goes | |
* great with responsive design! | |
* | |
* Adapted this from Zachstronaut (http://j.mp/RDztCB). | |
*/ | |
_gaq = [ | |
['_setAccount','UA-XXXXX-X'], | |
['_trackPageview'], | |
['_trackEvent', 'Browser Dimensions', 'Size', $(window).width() + 'x' + $(window).height()], // Track the browser width and height together | |
['_trackEvent', 'Browser Dimensions', 'Width', $(window).width(), $(window).width()], // Track the browser width and get average | |
['_trackEvent', 'Browser Dimensions', 'Height', $(window).height(), $(window).height()] // Track the browser height and get average | |
]; | |
(function(d,t){ | |
var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; | |
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js'; | |
s.parentNode.insertBefore(g,s) | |
}(document,'script')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment