Skip to content

Instantly share code, notes, and snippets.

@jsn789
Last active April 11, 2018 09:16
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/04b233752adace6fbb65b28263cadd4b to your computer and use it in GitHub Desktop.
Save jsn789/04b233752adace6fbb65b28263cadd4b to your computer and use it in GitHub Desktop.
GTM Custom JavaScript Variable For Scroll Tracking - non-Interaction logic
//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;
}
@jsn789
Copy link
Author

jsn789 commented Apr 11, 2018

@jsn789
Copy link
Author

jsn789 commented Apr 11, 2018

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