react-fathomv0.3.0
On this page
  1. Which Router Are You Using?
  2. Quick Comparison
  3. Import Path
  4. Environment Variables

Next.js

First-class Next.js support with automatic pageview tracking

Which Router Are You Using?

Next.js has two routing systems. Choose the guide that matches your project:

App Router

Next.js 13.4+ with the app/ directory. Uses Server Components and the new routing system.

Pages Router

Traditional Next.js with the pages/ directory. Requires Next.js 13 or newer.

Quick Comparison

FeatureApp RouterPages Router
ProviderNextFathomProviderAppFathomProvider
Route trackingNextFathomTrackViewApp (included)NextFathomTrackViewPages
Setup locationapp/layout.tsxpages/_app.tsx
Server ComponentsYes (provider is a Client Component)N/A

Import Path

All Next.js-specific exports come from react-fathom/next:

tsx
import {
  NextFathomProviderApp,
  NextFathomTrackViewApp,
  NextFathomTrackViewPages,
} from 'react-fathom/next'

The base FathomProvider, hooks, and components come from react-fathom:

tsx
import { FathomProvider, useFathom, TrackClick } from 'react-fathom'

Environment Variables

Store your site ID in an environment variable for production:

bash
NEXT_PUBLIC_FATHOM_SITE_ID=YOUR_SITE_ID
tsx
<NextFathomProviderApp siteId={process.env.NEXT_PUBLIC_FATHOM_SITE_ID}>

Environment variables must be prefixed with NEXT_PUBLIC_ to be available on the client side.

Last updated: October 8, 2026

By

Commune Software