function anonymous(event ) { return (function () { var quarters = 0; var scrollHeight, quarterHeight, scrollDistance, divisible, scrollPercent; // Debounce function function debounce(func, wait) { var timeout; return function () { var context = this, args = arguments; clearTimeout(timeout); timeout = setTimeout(function () { func.apply(context, args); }, wait); }; } // Handler function for the debounced scroll event function handleScroll() { scrollHeight = document.documentElement.scrollHeight - window.innerHeight; quarterHeight = scrollHeight / 4; scrollDistance = window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop; divisible = Math.trunc(scrollDistance / quarterHeight); if (quarters < divisible && divisible !== Infinity) { scrollPercent = divisible * 25; heap.track('Scroll Depth', { percent: scrollPercent }); quarters++; } } // Debounce the scroll event var debouncedScroll = debounce(handleScroll, 250); // Adjust the debounce time (e.g., 250 milliseconds) // Add the debounced scroll event listener document.addEventListener("scroll", debouncedScroll); })(); }