Skip to content

<TrackbridgePageViews />

Fires trackPageView on every Next.js route change. Internally a thin client component that subscribes to usePathname() and calls tracker.trackPageView({ path: pathname }) whenever it updates.

Drop it once inside <TrackbridgeProvider>. There are no props.

import { TrackbridgePageViews } from '@trackbridge/sdk/next';
<TrackbridgePageViews />;
  • Renders nothing (return null).
  • Calls tracker.trackPageView({ path: pathname }) on mount and whenever pathname changes.
  • The tracker handles dedup of consecutive identical paths internally, so React 18 strict-mode double-mount is a no-op.
  • Returns immediately if ga4MeasurementId was not configured (debug-warns under debug: true).

The component does not include search params in the path by default — usePathname() from next/navigation returns the pathname only. If you want search params, wire trackPageView manually with useSearchParams() instead.

app/layout.tsx
import { TrackbridgeProvider, TrackbridgePageViews } from '@trackbridge/sdk/next';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<TrackbridgeProvider config={config}>
<TrackbridgePageViews />
{children}
</TrackbridgeProvider>
</body>
</html>
);
}