React Native
Full React Native support with offline event queuing
react-fathom provides full React Native support with a hidden WebView that loads Fathom's official tracking script, ensuring compatibility with Fathom Analytics.
React Native support uses a WebView-based approach. Events are queued until the WebView is ready, then sent automatically.
Installation
Install react-fathom and the required WebView dependency:
bash
npm install react-fathom react-native-webviewFor iOS, install CocoaPods dependencies:
bash
cd ios && pod installBasic Setup
tsx
import { NativeFathomProvider } from 'react-fathom/native'
function App() {
return (
<NativeFathomProvider
siteId="YOUR_SITE_ID"
debug={__DEV__}
onReady={() => console.log('Fathom ready!')}
onError={(err) => console.error('Fathom error:', err)}
>
<YourApp />
</NativeFathomProvider>
)
}How It Works
The NativeFathomProvider:
- Renders a hidden WebView (0x0 pixels) that loads the Fathom script
- Queues all tracking calls until the WebView is ready
- Automatically flushes the queue when the script loads
- Provides the same
useFathomhook API as web
Tracking Events
Use the same hooks as web:
tsx
import { useFathom } from 'react-fathom/native'
function PurchaseButton({ price }) {
const { trackEvent, trackGoal } = useFathom()
const handlePurchase = () => {
trackEvent('purchase-tap', { _value: price })
trackGoal('PURCHASE', price)
}
return (
<TouchableOpacity onPress={handlePurchase}>
<Text>Buy Now</Text>
</TouchableOpacity>
)
}Provider Props
| Prop | Type | Description |
|---|---|---|
siteId | string | Your Fathom site ID (required) |
debug | boolean | Enable debug logging |
trackAppState | boolean | Auto-track app foreground/background |
loadOptions | LoadOptions | Options passed to fathom.load() |
scriptDomain | string | Custom domain (default: cdn.usefathom.com) |
defaultPageviewOptions | PageViewOptions | Default pageview options |
defaultEventOptions | EventOptions | Default event options |
onReady | () => void | Called when Fathom script loads |
onError | (error: string) => void | Called on script load error |
clientRef | MutableRefObject | Ref for direct client access |
Next Steps
- Navigation Tracking — Track React Navigation screen changes
- App State Tracking — Track foreground/background
- Advanced Setup — Custom WebView configuration
Last updated: October 8, 2026