Last active
December 14, 2015 05:38
-
-
Save derekjohnson/5036597 to your computer and use it in GitHub Desktop.
Small snippet to log an event in Google Analytics when a browser window is resized. It's often assumed designers and developers are the only people who resize the browser to see responsive web design in action. Let's test that assumption.
This file contains hidden or 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
if(window.addEventListener) { // correlates with media query support | |
var timer = false | |
, resize_monitor = function() { | |
if(timer) { | |
clearTimeout(timer); | |
} | |
timer = setTimeout(function() { _gaq.push(['_trackEvent', 'Resize', 'Resize', 'Resized']); }, 100); | |
// or log a pageview on a non-existant page if you prefer | |
// timer = setTimeout(function() { _gaq.push(['_trackPageview', '/resized.html']); }, 100); | |
} | |
; | |
window.addEventListener('resize', resize_monitor, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment