Next.js — Page views
Next.js can track page views automatically on route changes, or you can use hooks for manual control.Automatic: trackPageViews
WithSignalNextProvider, set trackPageViews={true} (default) to send a $pageview on every client-side route change:
Optional: trackSearchParams
SettrackSearchParams={true} to include URL search params in page view events. This uses useSearchParams(), so the tracker must be inside a Suspense boundary. The provider handles this when trackSearchParams is true.
Manual: usePageView and usePageViewWithSearchParams
For more control, use the hooks re-exported from@signal-js/nextjs/client:
- usePageView(options?) — Sends
$pageviewwhen the component mounts and when pathname changes. Options:trackSearchParams,additionalProperties. - usePageViewWithSearchParams(options?) — Same but always includes search params; must be used inside a Suspense boundary.
$pageview_product), use useSignalCapture() and call capture('$pageview_product', { ... }) inside a useEffect when the route or context changes.
See also
- Initialization — Provider setup
- Configuration — trackPageViews and trackSearchParams
