Skip to content

Instantly share code, notes, and snippets.

@derekjohnson
Last active December 14, 2015 05:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save derekjohnson/5036597 to your computer and use it in GitHub Desktop.
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.
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