MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / ScrollTracker

Function ScrollTracker

apps/public/src/components/scroll-tracker.tsx:7–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { useEffect, useRef } from 'react';
6
7export function ScrollTracker() {
8 const { track } = useOpenPanel();
9 const pathname = usePathname();
10 const hasFired = useRef(false);
11
12 useEffect(() => {
13 hasFired.current = false;
14
15 const handleScroll = () => {
16 if (hasFired.current) {
17 return;
18 }
19
20 const scrollTop = window.scrollY;
21 const docHeight =
22 document.documentElement.scrollHeight - window.innerHeight;
23 const percent =
24 docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
25
26 if (percent >= 50) {
27 hasFired.current = true;
28 track('scroll_half_way', { percent: Math.round(percent) });
29 }
30 };
31
32 window.addEventListener('scroll', handleScroll, { passive: true });
33 return () => window.removeEventListener('scroll', handleScroll);
34 }, [track, pathname]);
35
36 return null;
37}

Callers

nothing calls this directly

Calls 2

useOpenPanelFunction · 0.90
addEventListenerMethod · 0.80

Tested by

no test coverage detected