Scroll Depth Reporter


ScrollDepthReporter

The ScrollDepthReporter component provides automatic scroll depth tracking for engagement analytics. It monitors how far users scroll down the page and reports key milestones to the analytics system.

Features:

Basic Usage

---
import { ScrollDepthReporter } from '@dynamic-type/ddi';
---

<!-- Add the reporter component once per page -->
<ScrollDepthReporter />

<!-- That's it! Scroll depth will be tracked automatically -->

Tracked Thresholds

The component tracks when users reach these scroll depth percentages:

Each threshold is only reported once per page view.

How It Works

The ScrollDepthReporter:

  1. Calculates the scrollable height of the page
  2. Monitors scroll position using a passive event listener
  3. Throttles position checks using requestAnimationFrame for performance
  4. Tracks when each threshold is reached for the first time
  5. Calls trackEvent() with the scroll depth percentage
  6. Cleans up all listeners and state when the component unmounts

Analytics Events

When a threshold is reached, the component sends an event with:

Scroll depth tracking demonstration

Scroll depth tracking is active on this page. Check your browser’s developer tools and server logs (with DEBUG log level) to see tracking events fire as you scroll through different sections.

Events you’ll see:

Each threshold is tracked only once per page view, so scrolling back up won’t trigger duplicate events.

25% Milestone Keep scrolling to trigger more tracking events…

## 50% Milestone Halfway through the page!
## 75% Milestone Almost there…

95% Milestone You’ve reached the end! All thresholds should now be tracked.