The main function to create a tracker instance with your desired configuration.
const [{ Provider, DOMEvent, Click, Impression, PageView, SetContext }, useTracker] = createTracker({
init,
send,
DOMEvents,
impression: {
onImpression,
options,
},
pageView: {
onPageView,
},
batch,
});- Type:
(initialContext: Context, setContext: SetContext) => void | Promise<void> - Optional
- Function executed before any events happen
- If it returns a promise, events will be delayed until the promise resolves
- Type:
(params: EventParams | (context: Context) => EventParams, context: Context, setContext: SetContext) => TaskReturnType - Optional
- Standard function to send events
- If it returns a promise, events will be delayed until the promise resolves
- Type:
DOMEvents - Optional
- Collection of standard React DOM events (
onClick,onMouseEnter, etc.) - Each handler is executed when that event occurs on a
<Track.DOMEvent type=[event type]> - If a handler returns a promise, subsequent event callbacks will be delayed until it resolves
Configuration for impression tracking:
-
onImpression
- Type:
(params: EventParams | (context: Context) => EventParams, context: Context, setContext: SetContext) => TaskReturnType - Optional
- Executed when impression occurs on a
<Track.Impression>child - Promise return value will delay subsequent callbacks
- Type:
-
options
- Type:
ImpressionOptions - Optional
- Configuration options for impression tracking:
threshold: Percentage of visibility needed (default: 0.2)freezeOnceVisible: Freeze intersection state after visibility (default: true)initialIsIntersecting: Initial intersection state (default: false)
- Type:
Configuration for page view tracking:
- Type:
(params: EventParams | (context: Context) => EventParams, context: Context, setContext: SetContext) => TaskReturnType - Optional
- Executed when
<Track.PageView>is mounted - Promise return value will delay subsequent events
Configuration for event batching:
- Type:
BatchConfig - Optional
- Properties:
enable: Enable batching (default: false)interval: Flush interval in ms (default: 3000)thresholdSize: Max batch size (default: 25)onFlush: Function to handle batch flush (required if enabled)onError: Error handler (optional)
The createTracker function returns a tuple containing:
-
An object with tracking components:
-
The custom hook