Skip to content

Instantly share code, notes, and snippets.

@blissjaspis
Last active March 17, 2020 06:56
Show Gist options
  • Save blissjaspis/b5a6cb42f8b03db0de3b48ccd7db554f to your computer and use it in GitHub Desktop.
Save blissjaspis/b5a6cb42f8b03db0de3b48ccd7db554f to your computer and use it in GitHub Desktop.
Spy Depth Scroll
/**
* Track depth scroll
*/
var currentDepthScroll = 0;
function trackDepthScroll() {
var bottom = window.pageYOffset + window.innerHeight;
var height = document.documentElement.clientHeight;
var percent = (bottom/height)*100;
var done25 = false;
var done50 = false;
var done75 = false;
var done100 = false;
if (percent >= 25 && currentDepthScroll < 25 && done25 == false) {
done25 = true;
currentDepthScroll = 25;
console.log("GA Type : "+ window.GAPageType);
console.log('Scroll Depth 25%');
}
if (percent >= 50 && currentDepthScroll < 50 && done50 == false) {
done50 = true;
currentDepthScroll = 50;
console.log('Scroll Depth 50%');
}
if (percent >= 75 && currentDepthScroll < 75 && done75 == false) {
done75 = true;
currentDepthScroll = 89;
console.log('Scroll Depth 75%');
}
if (percent >= 100 && currentDepthScroll < 99 && done100 == false) {
done100 = true;
currentDepthScroll = 100;
console.log('Scroll Depth 100%');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment