React — Page views
Track page views when components mount (e.g. for SPA navigation) usingusePageView. For custom events tied to a specific event name, use useTrackEvent.
usePageView
Track a$pageview (or $pageview_<name>) when the component mounts. Useful for product or article pages where the “page” is a route or a key piece of content.
- pageName (
stringoptional) — If provided, the event is$pageview_<pageName>; otherwise$pageview. - properties (
Record<string, unknown>optional) — Extra properties (e.g.productId,productName).
$current_url, $pathname, and $title when available. It runs when the component mounts and when dependencies (pageName, properties) change. Note: properties is compared by reference. If you pass an object literal (e.g. usePageView('product', { productId: product.id })), a new object is created every render and the effect may run repeatedly. Memoize with useMemo or pass a stable reference to avoid duplicate page views.
useTrackEvent
Get a typed capture function for a specific event name. Use it when you want to fire one event type from a component (e.g.product_viewed) with different properties.
- eventName (
string) — The event name (e.g.'product_viewed'). - Returns a function
(properties?: T) => voidthat captures that event with the given properties.
useSignalSession
For session info (e.g.sessionId, windowId, sessionDuration, isRecording) use useSignalSession() from @signal-js/react. See the main React integration for the full hooks list.
See also
- Capture — Custom events
- Initialization — Provider setup
