Hooks

mixpanel:pageview

Context and lifecycle of the automatic router pageview hook.

mixpanel:pageview is called before an automatic router pageview is sent. See Pageviews for usage examples.

Type

Signature
interface RuntimeNuxtHooks {
  'mixpanel:pageview': (
    context: MixpanelPageviewContext<RouteLocationNormalized>
  ) => void | Promise<void>
}
Type import
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

HookArgumentEnvironmentPageview strategy
mixpanel:pageviewMixpanelPageviewContext<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.

The hook can be registered in a client or universal Nuxt plugin, but is not invoked during SSR. A server-only plugin does not register the handler in the browser.

Parameters

context

Type: MixpanelPageviewContext<RouteLocationNormalized>

PropertyTypeDescription
routeRouteLocationNormalizedDestination route; read-only.
propertiesRecord<string, unknown>Mutable properties sent with the pageview.
skipbooleanOmit the event when true; initially false.
signalAbortSignalAborted 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:

  1. SDK page properties.
  2. $mp_autocapture.
  3. route_name.
  4. Page meta, merged from parent to child.
  5. Hook properties.
Copyright © 2026