react-fathomv0.3.0
On this page
  1. FathomWebView
  2. Props
  3. Ref Methods (FathomWebViewRef)
  4. createWebViewClient
  5. Parameters
  6. Options
  7. Return Value (WebViewFathomClient)
  8. useNavigationTracking
  9. Options
  10. useAppStateTracking
  11. Options
  12. Types
  13. FathomClient
  14. WebViewFathomClient
  15. Re-exported Types

Native API

API reference for React Native-specific exports from react-fathom/native.

FathomWebView

Hidden WebView component that loads the Fathom Analytics script.

tsx
import { FathomWebView, type FathomWebViewRef } from 'react-fathom/native'

const webViewRef = useRef<FathomWebViewRef>(null)

<FathomWebView
  ref={webViewRef}
  siteId="YOUR_SITE_ID"
  onReady={() => console.log('Ready!')}
  onError={(err) => console.error(err)}
  debug={__DEV__}
/>

Props

PropTypeRequiredDescription
siteIdstringYesYour Fathom site ID
loadOptionsLoadOptionsNoOptions passed to fathom.load()
scriptDomainstringNoCustom domain (default: cdn.usefathom.com)
onReady() => voidNoCalled when script loads
onError(error: string) => voidNoCalled on error
debugbooleanNoEnable debug logging

Ref Methods (FathomWebViewRef)

MethodDescription
trackPageview(opts?)Track a pageview
trackEvent(eventName, opts?)Track a custom event
trackGoal(code, cents)Track a goal conversion
blockTrackingForMe()Block tracking for user
enableTrackingForMe()Enable tracking for user
isReady()Check if WebView is ready

createWebViewClient

Factory function to create a client that communicates with a FathomWebView.

tsx
import { createWebViewClient } from 'react-fathom/native'

const client = createWebViewClient(() => webViewRef.current, { debug: true })

Parameters

ParameterTypeDescription
getWebViewRef() => FathomWebViewRef | nullFunction returning the WebView ref
optionsWebViewClientOptionsConfiguration options

Options

OptionTypeDefaultDescription
debugbooleanfalseEnable debug logging
enableQueuebooleantrueQueue commands before WebView ready
maxQueueSizenumber100Maximum queued commands

Return Value (WebViewFathomClient)

Standard FathomClient methods plus:

MethodDescription
processQueue()Manually process queued commands (returns count)
getQueueLength()Get current queue length
setWebViewReady()Signal WebView is ready (flushes queue)

useNavigationTracking

Hook to track React Navigation screen changes as pageviews.

tsx
import { useNavigationTracking } from 'react-fathom/native'

useNavigationTracking({
  navigationRef,
  transformRouteName: (name) => `/screens/${name}`,
})

Options

OptionTypeRequiredDescription
navigationRefRefObjectYesReact Navigation container ref
transformRouteName(name: string) => stringNoTransform route names
shouldTrackRoute(name: string, params?: object) => booleanNoFilter routes to track
includeParamsbooleanNoInclude params in URL (default: false)

See Navigation Tracking for detailed usage.

useAppStateTracking

Hook to track app foreground/background state changes.

tsx
import { useAppStateTracking } from 'react-fathom/native'

useAppStateTracking({
  foregroundEventName: 'app-resumed',
  backgroundEventName: 'app-paused',
})

Options

OptionTypeDefaultDescription
foregroundEventNamestring'app-foreground'Event for foreground
backgroundEventNamestring'app-background'Event for background
eventOptionsEventOptions-Additional event options
onStateChange(state) => void-Callback on state change

See App State Tracking for detailed usage.

Types

FathomClient

Interface for Fathom client implementations:

tsx
interface FathomClient {
  load: (siteId: string, options?: LoadOptions) => void
  trackPageview: (opts?: PageViewOptions) => void
  trackEvent: (eventName: string, opts?: EventOptions) => void
  trackGoal: (code: string, cents: number) => void
  setSite: (id: string) => void
  blockTrackingForMe: () => void
  enableTrackingForMe: () => void
  isTrackingEnabled: () => boolean
}

WebViewFathomClient

Extends FathomClient with queue management:

tsx
interface WebViewFathomClient extends FathomClient {
  processQueue: () => number
  getQueueLength: () => number
  setWebViewReady: () => void
}

Re-exported Types

These types are re-exported from fathom-client for convenience:

tsx
import type {
  EventOptions,
  LoadOptions,
  PageViewOptions,
} from 'react-fathom/native'

Last updated: October 8, 2026

By

Commune Software