Getting Started
Install and set up react-fathom in your application.
Installation
Install react-fathom and its peer dependency fathom-client:
npm install react-fathom fathom-clientPeer 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.
| Package | Version | Required for |
|---|---|---|
react | >= 16.8 | All |
react-dom | >= 16.8 | Web only |
fathom-client | >= 3.0.0 | Web only (not needed for React Native) |
next | >= 13.0.0 | Next.js providers only |
react-router-dom | >= 6.0.0 | React Router / Remix only |
@reach/router | >= 1.3.0 | Gatsby only |
gatsby | >= 4.0.0 | Gatsby only |
@tanstack/react-router | >= 1.0.0 | TanStack Router only |
react-native | >= 0.60.0 | React Native only |
react-native-webview | >= 11.0.0 | React 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:
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:
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:
<FathomProvider siteId={process.env.REACT_APP_FATHOM_SITE_ID}>For Next.js, use the NEXT_PUBLIC_ prefix:
# .env.local
NEXT_PUBLIC_FATHOM_SITE_ID=YOUR_SITE_ID<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:
<FathomProvider
siteId="YOUR_SITE_ID"
clientOptions={{
includedDomains: ['localhost', 'yourdomain.com']
}}
>Last updated: October 8, 2026