Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

browser window size in google analytics?

We're trying to capture a report of actual browser window size in Google Analytics. I know they've got their in-page analytics, but that doesn't provide data, just a visualization. Anyone know if we're missing something or if we need to add this as a custom event?

Is this really necessary?

<script type="text/javascript">
 var width  = window.innerWidth  || document.body.clientWidth;
 var height = window.innerHeight || document.body.clientHeight;

 width  = Math.round(width/100)*100;
 height = Math.round(height/100)*100;

 var size = width + "x" + height;
 _gaq.push(['_trackEvent', 'Browser Size', 'Range', size]);
</script>
like image 708
tlhmode Avatar asked Oct 21 '13 14:10

tlhmode


1 Answers

You do need to add a custom event. I tried the javascript you had, but it messed with Google Analytic's Bounce Rate. You need to pass the opt_noninteraction variable as "true", otherwise Google considers the event a user interaction. Tracking the browser window size is not a user interaction and should be excluded from the bounce rate calc.

Here is the modified code:

<script>
var width = window.innerWidth || document.body.clientWidth;
var height = window.innerHeight || document.body.clientHeight;
width  = Math.round(width/10)*10;
height = Math.round(height/10)*10; //Using a 10 pixel granularity

var size = width + "x" + height;
_gaq.push(['_trackEvent', 'Browser Size', 'Range', size,, true]); //don't count in Bounce Rate
</script>
like image 187
marksbren Avatar answered Sep 18 '22 18:09

marksbren