Basic Usage
Get a stable function for tracking events:Why useTrack?
In React, functions created in components get recreated every render. This causes problems:useTrack returns a stable function reference that never changes, preventing unnecessary re-renders.
The useCallback Explanation
In React,useCallback memoizes functions so they don’t get recreated every render:
useTrack already uses useCallback internally, so you get a stable track function automatically.
Tracking Events
Track with event name and properties:Flush Option
Force immediate sending for critical events:Passing to Children
Safe to pass down to child components:track is stable, child components won’t re-render unnecessarily.
Common Patterns
Button Click
Form Submission
Page View
track is stable, this effect only runs once when the component mounts.
Feature Usage
With Template Events
Access template methods through the client:useTrack for custom events: