Last active
August 29, 2015 14:01
-
-
Save balsama/5221f66d8c7e7ec8cfb3 to your computer and use it in GitHub Desktop.
Track actual browser width (not screen resolution) in Google Analytics.
This file contains 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
/** | |
* 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