react-fathomv0.3.0
On this page
  1. Installation
  2. Peer Dependencies
  3. Basic Setup
  4. 1. Get Your Site ID
  5. 2. Add the Provider
  6. 3. Track Events
  7. Next Steps
  8. Environment Variables
  9. Local Development

Getting Started

Install and set up react-fathom in your application.

Installation

Install react-fathom and its peer dependency fathom-client:

bash
npm install react-fathom fathom-client

Peer Dependencies

Use Node.js 20 or newer. Install the peer dependencies for the integrations you use; React Native requires react-native-webview only when using the native entrypoint.

PackageVersionRequired for
react>= 16.8All
react-dom>= 16.8Web only
fathom-client>= 3.0.0Web only (not needed for React Native)
next>= 13.0.0Next.js providers only
react-router-dom>= 6.0.0React Router / Remix only
@reach/router>= 1.3.0Gatsby only
gatsby>= 4.0.0Gatsby only
@tanstack/react-router>= 1.0.0TanStack Router only
react-native>= 0.60.0React Native only
react-native-webview>= 11.0.0React Native only

Basic Setup

1. Get Your Site ID

Your Fathom site ID is an 8-character alphanumeric string (e.g., ABCD1234). Find it in your Fathom dashboard under Settings → Site ID.

2. Add the Provider

Wrap your application with FathomProvider:

tsx
import { FathomProvider } from 'react-fathom'

function App() {
  return (
    <FathomProvider siteId="YOUR_SITE_ID">
      <YourApp />
    </FathomProvider>
  )
}

3. Track Events

Use the useFathom hook to track custom events:

tsx
import { useFathom } from 'react-fathom'

function SignUpButton() {
  const { trackEvent } = useFathom()

  return <button onClick={() => trackEvent('signup-click')}>Sign Up</button>
}

Pageviews are tracked automatically by default.

Next Steps

  • React usage guide — Hooks and declarative components
  • React Router integration — Automatic pageview tracking for React Router and Remix
  • Gatsby integration — Automatic pageview tracking for Gatsby
  • TanStack Router integration — Type-safe routing with automatic tracking
  • Next.js integration — App Router and Pages Router
  • React Native setup — Mobile apps with offline queuing
  • API Reference — Full provider props and options

Environment Variables

For production apps, store your site ID in an environment variable:

tsx
<FathomProvider siteId={process.env.REACT_APP_FATHOM_SITE_ID}>

For Next.js, use the NEXT_PUBLIC_ prefix:

bash
# .env.local
NEXT_PUBLIC_FATHOM_SITE_ID=YOUR_SITE_ID
tsx
<FathomProvider siteId={process.env.NEXT_PUBLIC_FATHOM_SITE_ID}>

Local Development

By default, Fathom only tracks events from configured domains. To track during local development:

tsx
<FathomProvider
  siteId="YOUR_SITE_ID"
  clientOptions={{
    includedDomains: ['localhost', 'yourdomain.com']
  }}
>

Last updated: October 8, 2026

By

Commune Software