Skip to main content

Overview

The TrackScroll component monitors page scroll depth and tracks when users reach specific percentage milestones. Perfect for understanding content engagement and reading behavior.

Props

ReactNode
required
The content to render. The component tracks global page scroll, not scrolling within its children.
number[]
Array of percentage milestones to track. Each milestone is tracked only once per session.

Usage

Basic Scroll Tracking

Custom Milestones

Blog Post Engagement

Landing Page Analytics

Tracked Events

scroll_milestone

Tracked when a user reaches a scroll depth milestone:

Behavior

  • Tracks global window scroll, not container scroll
  • Each milestone is tracked only once per component instance
  • Uses passive scroll listeners for optimal performance
  • Automatically cleans up event listeners on unmount
  • Renders children as a React Fragment (no wrapper element)
  • Calculates scroll percentage based on total document height

Use Cases

  • Measure content engagement on long pages
  • Track blog post reading depth
  • Identify where users lose interest
  • Optimize content placement based on scroll data
  • A/B test content length and layout
  • Monitor landing page effectiveness
  • Trigger actions at specific scroll depths

Implementation Details

The component calculates scroll percentage using:
Milestones are tracked in a Set to ensure each is only reported once during the component’s lifetime.