Skip to content

Instantly share code, notes, and snippets.

@jsn789
Created April 11, 2018 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsn789/1206bcf53b476cccffb80668a13ae5d0 to your computer and use it in GitHub Desktop.
Save jsn789/1206bcf53b476cccffb80668a13ae5d0 to your computer and use it in GitHub Desktop.
GTM Custom JavaScript Variable For Scroll Tracking - Get Page Height
//Use as Event Action
function(){
pageHeight = 'Not Set',
//the height of the browser window's viewport - alternative is window.innerHeight
//https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
windowHeight = window.innerHeight
//the height of the document object. In most cases, this is equal to the <body> element of the document
//https://developer.mozilla.org/en-US/docs/Web/API/Document/height
documentHeight = document.documentElement.scrollHeight
heightRatio = documentHeight/windowHeight;
if(heightRatio >= 4){
pageHeight = 'Long';
}
else if(heightRatio >= 2){
pageHeight = 'Medium';
}
else{
pageHeight = 'Short';
}
return pageHeight;
}
@jsn789
Copy link
Author

jsn789 commented Apr 11, 2018

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