Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Track browser size in Google Analytics (not just screen size)

View gist:3910572
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
* 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
Something went wrong with that request. Please try again.