Last active
April 11, 2018 09:16
-
-
Save jsn789/04b233752adace6fbb65b28263cadd4b to your computer and use it in GitHub Desktop.
GTM Custom JavaScript Variable For Scroll Tracking - non-Interaction logic
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 a variable in the "Non-interaction Hit" field of the Event Tag | |
function(){ | |
nonInteraction = 'Not Set' | |
//the height of the browser window's viewport | |
//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 && {{Scroll Depth Threshold}} !== 25){ | |
//Page Height is "Long" and the user scrolled passed the 25% mark | |
nonInteraction = false; | |
} | |
else if(heightRatio >= 4 && {{Scroll Depth Threshold}} === 25){ | |
//Page Height is "Long", but only 25% of the page was scrolled | |
nonInteraction = true; | |
} | |
else if(heightRatio >= 2){ | |
//Page Height is "Medium" | |
nonInteraction = true; | |
} | |
else{ | |
//Page Height is "Short" | |
nonInteraction = true; | |
} | |
return nonInteraction; | |
} |
non-Interaction: true, when Page Height is Medium or Short as well as when Scroll Threshold is 25%.
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/1206bcf53b476cccffb80668a13ae5d0