Untitled
user_2557125
plain_text
a year ago
1.9 kB
2
Indexable
Never
//<![CDATA[ (function(d, w) { w.dataLayer = w.dataLayer || []; var scrollTwentyFive, scrollFifty, scrollSeventyFive, scrollOneHundred; const getScrollPercentage = function() { // Get the height of the window. var winHeight = w.innerHeight; // Get the height of the document. var docHeight = d.documentElement.scrollHeight; // Get the scroll position of the window. var scrollTop = d.documentElement.scrollTop; // Calculate the track length, which is the difference between the document height and the window height. var trackLength = docHeight - winHeight; // Calculate the percentage of the document that is currently scrolled. var pctScrolled = Math.floor(scrollTop / trackLength * 100); // Return the percentage. return pctScrolled; } d.addEventListener("DOMContentLoaded", function(){ w.addEventListener('scroll', function(e){ var scrollPercentage = getScrollPercentage(); if (scrollPercentage >= 25 && !scrollTwentyFive) { console.log('Do something for 25% scroll'); var _paq = w._paq || []; _paq.push(["trackEvent",'scroll','25','']); scrollTwentyFive = true; } if (scrollPercentage >= 50 && !scrollFifty) { console.log('Do something for 50% scroll'); var _paq = w._paq || []; _paq.push(["trackEvent",'scroll','50','']); scrollFifty = true; } if (scrollPercentage >= 75 && !scrollSeventyFive) { console.log('Do something for 75% scroll'); var _paq = w._paq || []; _paq.push(["trackEvent",'scroll','75','']); scrollSeventyFive = true; } if (scrollPercentage >= 100 && !scrollOneHundred) { console.log('Do something for 100% scroll (bottom of page)'); var _paq = w._paq || []; _paq.push(["trackEvent",'scroll','100','']); scrollOneHundred = true; } }); }); })(document, window); //]]>