PageView
Tracks page view events on component mount.
import { createTracker } from "@offlegacy/event-tracker";
const [Track] = createTracker({
pageView: {
onPageView: (params, context) => {
// Handle page view event
},
},
});
function App() {
return (
<Track.Provider initialContext={{}}>
<Track.PageView params={{ page: "/home" }} />
</Track.Provider>
);
}
Props
- With schema
params: SchemaParams | (context: Context) => SchemaParams
- Page view event parameters based on schemaschema: string
- A name of schema that will be used to validate the event parameters
- Without schema
params: EventParams | (context: Context) => EventParams
- Page view event parameters
enabled?: boolean | ((context: Context, params: EventParams) => boolean)
- Conditionally enable/disable event tracking (default:true
)debounce?: DebounceConfig
- Debounce configuration to prevent rapid successive eventsthrottle?: ThrottleConfig
- Throttle configuration to limit event frequency
Note: debounce
and throttle
are mutually exclusive and cannot be used together.
Tracking Options Examples
Conditional Tracking
<Track.PageView
params={{ page: "/dashboard", userId: "123" }}
enabled={(context) => context.trackingConsent === true}
/>
Debounced Page Views
<Track.PageView params={{ page: "/search-results" }} debounce={{ delay: 1000, leading: true, trailing: false }} />
Last updated on