Skip to Content
DocsComponentsPageView

PageView

Tracks a page view event when the component mounts. It is one of the event components returned as the first element of the createTracker tuple.

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> ); }

Reference

Props

PropTypeDescriptionRequired
enabledboolean | ((context: Context, params: EventParams) => boolean)Conditionally enable/disable event tracking (default: true)-
debounceDebounceConfigDebounce configuration to prevent rapid consecutive events-
throttleThrottleConfigThrottle configuration to limit event frequency-
schemastringSchema name for validating event parametersO

Note: debounce and throttle are mutually exclusive and cannot be used together. A type error will prevent invalid usage.

When using with schemas vs. without schemas, the params prop type differs.

With schema:

PropTypeDescription
paramsSchemaParams | (context: Context) => SchemaParamsSchema-based parameters

Without schema:

PropTypeDescription
paramsEventParams | (context: Context) => EventParamsStandard parameters

params (Required)

With schema:

  • Type: SchemaParams | (context: Context) => SchemaParams
  • Description: Schema-based parameters

Without schema:

  • Type: EventParams | (context: Context) => EventParams
  • Description: Event parameters

enabled

  • Type: boolean | ((context: Context, params: EventParams) => boolean)
  • Description: Conditionally enable or disable event tracking (default: true)

debounce

  • Type: DebounceConfig
  • Description: Configure debouncing to avoid multiple rapid event triggers.

throttle

  • Type: ThrottleConfig
  • Description: Configure throttling to limit event frequency.

schema

When using schemas:

  • Type: string
  • Description: Schema name used to validate event parameters.

Examples

Conditional Event

<Track.PageView params={{ page: "/dashboard", userId: "123" }} enabled={(context) => context.trackingConsent === true} />

Debounced Page View

<Track.PageView params={{ page: "/search-results" }} debounce={{ delay: 1000, leading: true, trailing: false }} />
Last updated on