Skip to content

Instantly share code, notes, and snippets.

@balsama
Last active August 29, 2015 14:01
Show Gist options
  • Save balsama/5221f66d8c7e7ec8cfb3 to your computer and use it in GitHub Desktop.
Save balsama/5221f66d8c7e7ec8cfb3 to your computer and use it in GitHub Desktop.
Track actual browser width (not screen resolution) in Google Analytics.
/**
* Creates a Google Analytics Event on page load that tracks which default
* Bootstrap screen width category the user's browser falls into.
*
* See http://getbootstrap.com/css/#grid-media-queries
*/
var width = window.innerWidth || document.body.clientWidth;
var bootstrapSize = 'Extra Small (xs)';
if (width >= 768) {
bootstrapSize = 'Small (sm)';
}
if (width >= 992) {
bootstrapSize = 'Medium (md)';
}
if (width >= 1200) {
bootstrapSize = 'Large (lg)';
}
_gaq.push(['_trackEvent', 'Bootstrap Browser Size', 'Page Requested', bootstrapSize]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment