Created
April 11, 2018 09:05
-
-
Save jsn789/1206bcf53b476cccffb80668a13ae5d0 to your computer and use it in GitHub Desktop.
GTM Custom JavaScript Variable For Scroll Tracking - Get Page Height
This file contains 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
//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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use together with:
https://gist.github.com/jsn789/04b233752adace6fbb65b28263cadd4b