Some checks failed
Build and Deploy / build (push) Has been cancelled
- Email capture popup with scroll (10%) and exit intent triggers - First name field and full tracking (UTM, device, time on page) - Mautic API integration for contact creation - GeoIP detection for country/region - 4 locale support (sr, en, de, fr) - Mautic tracking script in layout
29 lines
881 B
TypeScript
29 lines
881 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
export function useScrollDepth(threshold: number = 20): boolean {
|
|
const [hasReachedThreshold, setHasReachedThreshold] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const handleScroll = () => {
|
|
if (hasReachedThreshold) return;
|
|
|
|
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
|
|
const scrollPercent = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
|
|
|
|
if (scrollPercent >= threshold) {
|
|
setHasReachedThreshold(true);
|
|
}
|
|
};
|
|
|
|
window.addEventListener("scroll", handleScroll, { passive: true });
|
|
handleScroll();
|
|
|
|
return () => window.removeEventListener("scroll", handleScroll);
|
|
}, [threshold, hasReachedThreshold]);
|
|
|
|
return hasReachedThreshold;
|
|
}
|