Last active
October 18, 2018 14:30
-
-
Save simondahla/7888578 to your computer and use it in GitHub Desktop.
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
/* | |
Google Analytics Classic - Browser Viewport Size | |
Credit @beantin | |
CC BY 2.5 2013 | |
*/ | |
function viewport() { | |
var myWidth = 0, myHeight = 0; | |
if( typeof( window.innerWidth ) == 'number' ) { | |
//Non-IE | |
myWidth = window.innerWidth; | |
myHeight = window.innerHeight; | |
} else if( document.documentElement && | |
( document.documentElement.clientWidth | |
|| document.documentElement.clientHeight ) ) { | |
//IE 6+ in 'standards compliant mode' | |
myWidth = document.documentElement.clientWidth; | |
myHeight = document.documentElement.clientHeight; | |
} else if( document.body && | |
( document.body.clientWidth | |
|| document.body.clientHeight ) ) { | |
//IE 4 compatible | |
myWidth = document.body.clientWidth; | |
myHeight = document.body.clientHeight; | |
} | |
_gaq.push(['_trackEvent','Viewport','Size',myWidth+'x'+myHeight,, true]); | |
_gaq.push(['_trackEvent','Viewport','Width',myWidth+'x'+myHeight, myWidth, true]); | |
_gaq.push(['_trackEvent','Viewport','Height',myWidth+'x'+myHeight, myHeight, true]); | |
} |
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
/* | |
Google Analytics Universal - Browser Viewport Size | |
Credit @beantin | |
CC BY 2.5 2013 | |
//This is tracked by Universal Analytics by default | |
//This is only needed if you want to track this as separte events | |
*/ | |
function viewport() { | |
var myWidth = 0, myHeight = 0; | |
if( typeof( window.innerWidth ) == 'number' ) { | |
//Non-IE | |
myWidth = window.innerWidth; | |
myHeight = window.innerHeight; | |
} else if( document.documentElement && | |
( document.documentElement.clientWidth | |
|| document.documentElement.clientHeight ) ) { | |
//IE 6+ in 'standards compliant mode' | |
myWidth = document.documentElement.clientWidth; | |
myHeight = document.documentElement.clientHeight; | |
} else if( document.body && | |
( document.body.clientWidth | |
|| document.body.clientHeight ) ) { | |
//IE 4 compatible | |
myWidth = document.body.clientWidth; | |
myHeight = document.body.clientHeight; | |
} | |
//This is tracked by Universal Analytics by default | |
//This is only needed if you want to track this as separte events | |
ga('send', 'event', 'Viewport', 'Size', myWidth+'x'+myHeight, {'nonInteraction': 1}); | |
ga('send', 'event', 'Viewport', 'Width', myWidth+'x'+myHeight, myWidth, {'nonInteraction': 1}); | |
ga('send', 'event', 'Viewport', 'Height', myWidth+'x'+myHeight, myHeight, {'nonInteraction': 1}); | |
} |
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
<body onLoad="viewport();"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment