Skip to content

Instantly share code, notes, and snippets.

@cmattoon
Created August 15, 2013 15:38
Show Gist options
  • Save cmattoon/6241862 to your computer and use it in GitHub Desktop.
Save cmattoon/6241862 to your computer and use it in GitHub Desktop.
Update Google Analytics when browser orientation changes.
function checkOrientation() {
var w,o,t;
w = window;
o = (w.innerWidth > w.innerHeight) ? 'landscape' : 'portrait';
t = _gat._getTrackers()[0];
if (typeof(w.gao) == 'undefined') {
w.gao = o;
} else {
if (w.gao != o) {
w.gao = o;
if(typeof(_gat) == 'object') {
if(typeof(t) == 'object') {
t._trackPageview('orientation-' + o);
}
}
}
}
}
/*Minified ---
function checkOrientation(){var w,o,t;w=window;o=w.innerWidth>w.innerHeight?"landscape":"portrait";t=_gat._getTrackers()[0];if(typeof w.gao=="undefined")w.gao=o;else if(w.gao!=o){w.gao=o;if(typeof _gat=="object")if(typeof t=="object")t._trackPageview("orientation-"+o)}};
*/
@cmattoon
Copy link
Author

Usage:

$(window).resize(function() {
checkOrientation()
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment