Skip to content

Instantly share code, notes, and snippets.

@WolfieZero
Created October 18, 2012 09:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WolfieZero/3910572 to your computer and use it in GitHub Desktop.
Save WolfieZero/3910572 to your computer and use it in GitHub Desktop.
Track browser size in Google Analytics (not just screen size)
/**
* 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