mixpanel:pageview
mixpanel:pageview is called before an automatic router pageview is sent. See Pageviews for usage examples.
Type
interface RuntimeNuxtHooks {
'mixpanel:pageview': (
context: MixpanelPageviewContext<RouteLocationNormalized>
) => void | Promise<void>
}
import type { MixpanelPageviewContext } from 'mixpanel-nuxt/config'
MixpanelPageviewContext<Route> accepts a route type; its default is unknown. Nuxt automatically supplies RouteLocationNormalized in the hook declaration.
Execution
| Hook | Argument | Environment | Pageview strategy |
|---|---|---|---|
mixpanel:pageview | MixpanelPageviewContext<RouteLocationNormalized> | Browser | 'router' |
The hook runs for navigations selected by the tracking mode, page meta and autocapture URL filters. Excluded pages, cancelled navigations and URL changes outside the selected mode do not invoke it. Manual calls to track_pageview() do not invoke it either.
Handlers run in parallel while the page renders. The pageview waits for all handlers, page rendering, head updates and transitions. It is omitted if context.skip is true after the handlers finish.
Parameters
context
Type: MixpanelPageviewContext<RouteLocationNormalized>
| Property | Type | Description |
|---|---|---|
route | RouteLocationNormalized | Destination route; read-only. |
properties | Record<string, unknown> | Mutable properties sent with the pageview. |
skip | boolean | Omit the event when true; initially false. |
signal | AbortSignal | Aborted when a new navigation replaces this one; read-only. |
The initial properties contain $mp_autocapture: true, the route name when present, and properties from page meta.
Return value
Handlers return void or Promise<void>. Event changes are made through context; resolved values do not supply event properties.
Cancellation
A new navigation aborts the previous context's signal and drops its pending pageview.
A handler that never settles keeps the pageview pending until another navigation replaces it.
Errors
If a handler throws, the module logs the error and resets the properties to their pre-hook values. The pageview is still sent unless skip is set.
Property precedence
Later sources replace earlier properties with the same key:
- SDK page properties.
$mp_autocapture.route_name.- Page meta, merged from parent to child.
- Hook properties.