Overview
TheTrackView component automatically tracks when its children become visible in the viewport using the Intersection Observer API. Perfect for tracking impressions of content sections, ads, or important UI elements.
Props
ReactNode
required
The content to render and track visibility for.
string
default:"element_viewed"
The event name to track when the element becomes visible.
EventProperties
Additional properties to include with the tracked event.
number
Percentage of element that needs to be visible to trigger tracking (0 to 1). For example, 0.5 means 50% of the element must be visible.
number
default:1000
Delay in milliseconds before tracking the view event. Helps ensure the user actually saw the content rather than just scrolling past it.
Usage
Basic Usage
Custom Visibility Threshold
Track Content Section
Behavior
- Tracks visibility only once per component instance
- Uses Intersection Observer for efficient visibility detection
- Automatically cleans up observer on unmount
- Respects both threshold and delay before tracking
- Wraps children in a
<div>element with a ref for observation
Use Cases
- Track ad impressions
- Measure content engagement
- Monitor which sections users view
- A/B test visibility of different layouts
- Track scroll depth to specific elements