React Native Error Tracking installation
Install with the wizard
Run this command in your project directory to add PostHog to your React Native project. The wizard detects your framework, installs the SDK, and sets up your first events.
Or set it up manually by following the rest of this guide.
- 1
Install the package
RequiredInstall the PostHog React Native library and its dependencies:
- 2
Configure PostHog
RequiredPostHog is most easily used via the
PostHogProvidercomponent. Wrap your app with the provider:App.tsx - 3
Send events
RecommendedOnce installed, PostHog will automatically start capturing events. You can also manually send events using the
usePostHoghook:Component.tsx - 4
Set up exception autocapture
RecommendedClient-side configuration onlySupport for remote configuration in the error tracking settings requires SDK version 4.35.0 or higher.
You can autocapture exceptions by configuring the
errorTrackingwhen setting up PostHog:React NativeConfiguration options:
Option Description uncaughtExceptionsCaptures Uncaught exceptions ( ReactNativeGlobal.ErrorUtils.setGlobalHandler)unhandledRejectionsCaptures Unhandled rejections ( ReactNativeGlobal.onunhandledrejection)consoleCaptures console logs as errors according to the reported LogLevelnativeCrashesCaptures native iOS/Android crashes. Requires @posthog/react-native-pluginand uploaded native symbols (see below)Capturing native crashesnativeCrashescaptures native iOS and Android crashes that the JavaScript layer can't see. Beyond the config above, it needs:- The optional native plugin installed —
npx expo install @posthog/react-native-plugin@3(Expo) ornpm i @posthog/react-native-plugin@3(bare React Native). Plugin 3.0 requiresposthog-react-native4.88.4+, React Native 0.75+, iOS 15+, and Xcode 26+. On React Native 0.75 and 0.76, including Expo SDK 52, Android builds also need Kotlin 2.0 or later. If it's missing, native capture is a no-op and your JS-level autocapture is unaffected. - Your project's Enable exception autocapture setting enabled in error tracking settings — the same server-side setting that gates JavaScript autocapture.
- Native debug symbols uploaded at build time, so crash stack traces are readable. See native crash symbolication.
- The optional native plugin installed —
- 5
Set up error boundaries
OptionalYou can use the
PostHogErrorBoundarycomponent to capture rendering errors thrown by components:React NativeDuplicate errors with console captureIf you have both
PostHogErrorBoundaryandconsolecapture enabled in yourerrorTrackingconfig, render errors will be captured twice. This is because React logs all errors to the console by default. To avoid this, setconsole: []onerrorTracking.autocapture(for example,errorTracking: { autocapture: { console: [] } }) when usingPostHogErrorBoundary.Dev mode behaviorIn development mode, React propagates all errors to the global error handler even when they are caught by an error boundary. This means you may see errors reported twice in dev builds. This is expected React behavior and does not occur in production builds.
- 6
Manually capture exceptions
OptionalYou can manually capture exceptions using the
captureExceptionmethod:React NativeThis is helpful if you've built your own error handling logic or want to capture exceptions that are handled by your application code.
- 7
Future features
OptionalWe currently don't support the following features:
- No automatic source map uploads on React Native web
This will be added in a future release. We recommend you stay up to date with the latest version of the PostHog React Native SDK.
- 8
iOS dependency resolution for native crash capture
CocoaPods is becoming read-only. CocoaPods trunk becomes read-only on December 2, 2026, and
posthog-ios4.0 and later is only published through Swift Package Manager (SPM).
@posthog/react-native-plugin3.0 and later always resolvesposthog-iosthrough SPM, including on the CocoaPods path, so upgrading the plugin is enough. See Upgrading to@posthog/react-native-plugin3.0.Plugin 2.x stays on
posthog-ios3.x on every iOS dependency path, including the hybrid and full SPM setups, so switching paths doesn't bring newer iOS SDK versions. To getposthog-ios4.0 and later, upgrade to plugin 3.0.This change doesn't affect
@posthog/react-native-pluginreleases on npm or Android.
The optional @posthog/react-native-plugin package adds native features such as session replay and native crash capture. Install it as described in the guide for the feature that you use.
@posthog/react-native-plugin 3.0 and later requires React Native 0.75 or later and, on every iOS dependency path, Xcode 26 or later and an iOS 15 or later deployment target (macOS 12 or later for React Native macOS apps). See Upgrading to @posthog/react-native-plugin 3.0.
Then choose one iOS dependency path. From 3.0, posthog-ios always comes from Swift Package Manager; the path only decides how the plugin itself is installed:
- CocoaPods. CocoaPods builds the plugin from
node_modules. From@posthog/react-native-plugin3.0, the plugin's podspec addsposthog-iosas a Swift package, so CocoaPods never installsposthog-ios. In 2.x, CocoaPods installsposthog-ios3.x. This remains the default path, including for Expo. - CocoaPods with
posthog-iosthrough Swift Package Manager.@posthog/react-native-plugin2.x only. CocoaPods resolves the plugin, and Swift Package Manager resolvesposthog-ios. Needs React Native 0.75 or later and a CocoaPods project with dynamic frameworks. From 3.0, the CocoaPods path always does this. - Full Swift Package Manager. React Native's experimental Swift Package Manager integration resolves the plugin and
posthog-ios, without CocoaPods. Needs@posthog/react-native-plugin2.4.0 or later, Xcode 16 or later (Xcode 26 or later for plugin 3.0 and later), and an iOS 15.1 or later app deployment target.
PostHog verifies the full Swift Package Manager path with an iOS-only React Native 0.87.1 app and React Native Community CLI 20.2.0. This verification does not cover Expo or other React Native versions. Use the CocoaPods path unless you validate full Swift Package Manager for your configuration. On plugin 3.0, both paths get posthog-ios from Swift Package Manager.
CocoaPods
Use the standard React Native CocoaPods flow:
The plugin podspec adds posthog-ios for you. You do not need to add posthog-ios separately.
From @posthog/react-native-plugin 3.0, CocoaPods builds only the plugin's own code, and posthog-ios comes from Swift Package Manager:
- React Native's autolinking (
use_native_modules!) finds the plugin innode_modulesand reads its podspec from there. Nothing is downloaded from CocoaPods trunk, so its read-only date doesn't affect the plugin. - The podspec declares
posthog-ioswith React Native'sspm_dependencyhelper instead of as a pod. - During
pod install, React Native adds theposthog-iosSwift package (https://github.com/PostHog/posthog-ios.git, 4.2.x) toPods.xcodeprojand links it to the plugin's pod target. - Xcode fetches and builds
posthog-iosas a Swift package when you build, and records the version in your workspace'sPackage.resolved.
Static libraries, static frameworks and dynamic frameworks all work. Plugin 2.x adds posthog-ios 3.x as a CocoaPods dependency instead, unless you set posthog.useSpm (below).
CocoaPods with posthog-ios through Swift Package Manager
This path applies to @posthog/react-native-plugin 2.x only. From 3.0, the CocoaPods path already resolves posthog-ios through Swift Package Manager and the plugin ignores posthog.useSpm.
Add the following property to ios/Podfile.properties.json:
Add dynamic frameworks to your ios/Podfile:
Then install the pods:
This setting changes only how the plugin resolves posthog-ios. The plugin and other React Native dependencies still use CocoaPods.
Full Swift Package Manager
This path uses React Native's experimental CocoaPods-free iOS integration. Every native dependency in your app must support React Native's full Swift Package Manager integration. Use CocoaPods (or, on plugin 2.x, the hybrid path) if a dependency does not support it.
Install your JavaScript dependencies first. Make a clean commit or a backup of your iOS project before the conversion. Then run this command from the ios directory:
The --deintegrate option removes the complete CocoaPods integration from the iOS project. React Native then finds the plugin's ios/Package.swift manifest. Swift Package Manager resolves the plugin and posthog-ios. Do not run pod install for this path.
PostHog CI verifies this path with the configuration above. The verified app sets its deployment target to iOS 15.1. The plugin package manifest has a separate iOS 15 minimum. On the CocoaPods and hybrid paths, the plugin podspec's minimum is iOS 15 from @posthog/react-native-plugin 3.0, and iOS 13 in earlier versions.
Filtering native events with addBeforeSend
before_send runs only on events captured in JavaScript. Events the native SDKs capture themselves (native crash reports from the previous launch, push notification opens, and session replay) never reach it. To filter or edit those, add a native hook with PosthogReactNativePlugin.addBeforeSend (requires @posthog/react-native-plugin 3.0.0 or later). Fatal JavaScript errors, which the plugin sends natively, pass through both.
Hooks run in the order you add them. Return the event, changed or not, to send it, or null (nil in Swift) to drop it. On Android, a hook that throws drops the event. Add hooks before React Native starts, so they also see the crash reported from the previous launch.
On iOS, add the hook in application(_:didFinishLaunchingWithOptions:):
On Android, add it in MainApplication.onCreate:
Upgrading to @posthog/react-native-plugin 3.0
@posthog/react-native-plugin 3.0 uses posthog-ios 4.2.2 or a later 4.2.x version and posthog-android 4.2.3 or a later 4.2.x version. For before-and-after examples and a checklist, see the migration guide. The plugin requires:
posthog-react-native4.88.4 or later. The plugin reads the project token only fromprojectToken, whichposthog-react-nativesends from 4.88.4. With an older version, the plugin logssetup() needs sdkOptions.projectTokenand native features (session replay, native crash reports, fatal JavaScript error capture) stay off. JavaScript events are unaffected.- React Native 0.75 or later
- Xcode 26 or later, on every iOS dependency path
- An iOS 15 or later deployment target, and macOS 12 or later for React Native macOS apps
- Kotlin 2.0 or later on Android. React Native 0.75 and 0.76 templates, including Expo SDK 52, use Kotlin 1.9, so set
kotlinVersionto2.0.21and pin the Kotlin Gradle plugin to it. On Expo SDK 52,npx expo prebuild --cleanwipes these edits, so make them with a config plugin or upgrade to Expo SDK 53 or later. The migration guide has the details.
On iOS, the plugin now always resolves posthog-ios through Swift Package Manager:
- Remove
"posthog.useSpm"fromios/Podfile.properties.jsonif you set it. The plugin no longer reads it. - The plugin no longer needs
use_frameworks! :linkage => :dynamic. Keep it only if another dependency needs it. - Before you upgrade, remove the legacy
posthog-react-native-session-replaypackage and anypod 'PostHog'line in your Podfile. Both installposthog-ios3.x, which clashes with the plugin's 4.x, sopod installstops with an error that names the conflicting pod. If your own native code importsPostHog, addposthog-iosto that target as a Swift package instead. The check only sees pods your Podfile adds directly. Another pod that depends onPostHogstill installs, and the Xcode build then fails withRedefinition of module 'PostHog', so remove or update that pod too. - Remove these Podfile settings if you use them, because
pod installnow fails with them::generate_multiple_pod_projects => true,:deduplicate_targets => false, and targets that use the plugin with differentplatformoruse_frameworks!settings. - Make sure build machines can reach
https://github.com/PostHog/posthog-ios.git, because Xcode now fetchesposthog-iosfrom there. - If your app target has
import PostHog, check that it still compiles. React Native's helper adds the package only to the plugin's pod target. This case isn't tested, but if the import no longer resolves, addposthog-iosto your app target as a Swift package with a compatible version. - Apps on React Native's full Swift Package Manager integration have no Podfile to change. Build with Xcode 26 or later, and resolve packages again if
Package.resolvedstill pinsposthog-ios3.x. If your app target addsposthog-iosas a package too, require 4.2.2 or a later 4.2.x version, because the plugin pinsposthog-iosto 4.2.x. These apps no longer bundle the native surveys fromposthog-ios, which the plugin doesn't use because surveys render in JavaScript. - If a custom dSYM upload script calls
${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh, change it to${BUILD_DIR%/Build/*}/SourcePackages/checkouts/posthog-ios/build-tools/upload-symbols.sh. TheuploadNativeSymbolsbuild phase from the Expo config plugin already checks both paths.
Apps that use the plugin only through posthog-react-native need no code changes. If your code calls the plugin directly:
Call
setup()instead of the removedstart()method.setup()takes three arguments and reads the replay settings frompluginConfig.sessionReplay. Replay starts only whensessionReplay.enabledistrue, which defaults tofalse:TypeScriptPass
throttleDelayMsinstead ofiOSdebouncerDelayMsorandroidDebouncerDelayMs, which the plugin no longer reads.posthog-react-nativestill maps these deprecated options tothrottleDelayMs.Pass the project token in
sdkOptionsasprojectToken. The plugin no longer reads the deprecatedapiKey.
On iOS, native uploads (session replay and native crash reports) pause while cellular data is turned off for your app, instead of sending requests that fail.
On iOS and Android, events that the plugin sends natively go to capture v1 (/i/v1/analytics/events) in posthog-ios 4.0 and posthog-android 4.0. These are native crash reports, fatal JavaScript errors, iOS rage clicks ($rageclick), and push-opened events. Events captured in JavaScript still go to /batch. If you self-host PostHog or use a reverse proxy:
- Forward
/i/v1/*to PostHog. - Pass these request headers through unchanged:
Authorization,Content-Type,Content-Encoding,User-Agent,PostHog-Sdk-Info,PostHog-Attempt,PostHog-Request-IdandPostHog-Request-Timestamp. - Return PostHog's response status, body and
Retry-Afterheader unchanged. The SDKs read them to decide which events to retry or drop, and drop the events on a2xxwhose body isn't PostHog's. - Proxy setups from our guides before October 29, 2026 strip
Authorization, so PostHog answers401and drops the native events. Update yours from the current guide. - Don't rely on a custom
Authorizationheader inrequestHeadersfor these requests. The SDK replaces it withBearer <projectToken>, so authenticate your proxy with a different header. Session replay uploads to/s/still send yourAuthorizationheader. - Don't redirect these requests to another origin. The SDKs follow only a 307 or 308 redirect to the same origin as
host, and drop the events on any other redirect. - If the path isn't served and the proxy answers
404, each running app retries about every 30 seconds, and the native events stay queued on the device only until a full queue evicts them (1000 events by default), oldest first. Other errors, such as401,403or405, drop them.
These native events also change shape:
- A native event whose distinct ID is empty, whitespace-only or over 200 UTF-8 bytes is dropped. Plugin 2.x shortened a long ID to 200 characters and kept the event. JavaScript events still shorten it, so with a long distinct ID, such as a JWT, your app keeps its JavaScript events but loses its native ones. Keep distinct IDs at 200 bytes or shorter.
- On iOS, a property whose value is
nullis left out instead of sent asnull. On Android, anullelement in a list is kept at its position instead of being removed.$setand$set_oncestill sendnullvalues.
Native events report $locale as the device's preferred language, as a full language tag with region, such as de-CH or zh-Hant-TW instead of de or zh-TW. On iOS this used to be the language your app bundle resolved, so an English-only app on a French device now sends fr-FR instead of en. Native events also add $app_language, the language your app shows, once you call setAppLanguage(). On Android, $locale also uses the current codes he, id and yi instead of the legacy iw, in and ji, so in-ID becomes id-ID. Update insights that filter on a two-letter $locale or on those codes.
If your app creates PostHog clients for more than one project, native events take $app_language only from clients of the project the native SDK was set up for.
If native code in your app, or a native library it uses, calls posthog-ios or posthog-android directly, update it for 4.0. See the posthog-ios migration guide and the posthog-android migration guide. Android code compiled against posthog-android 3.x fails at runtime with errors such as NoSuchMethodError.
Session replay records only masked screenshots on iOS and Android, because posthog-ios 4.0 and posthog-android 4.0 remove wireframe capture. The plugin already forced screenshot mode, so recordings keep the same mode. If native code in your app sets screenshotMode (iOS) or screenshot (Android), remove it, because it no longer compiles.
On iOS, secure text inputs stay masked inside a ph-no-mask view. On Android, touches inside a ph-no-capture view are no longer recorded, as on iOS since plugin 2.13.2. If you upgrade from plugin 2.13.1 or earlier, iOS masking also covers content a masked view draws outside its bounds, such as unclipped images, layer shadows and button titles. If a masked view sits inside a view backed by its own CALayer subclass, such as a lottie-react-native animation, the SDK masks the whole window for that frame, and fast scrolling on such a screen may drop replay frames.
The plugin ignores sessionReplayConfig.screenshotModeBackgroundCapture, because posthog-ios 4.0 removed background screenshot capture, and posthog-react-native logs a warning if you set it. Remove it, or try the experimental iOSCaptureMethod: 'gpu' (see Troubleshooting).
In iOS native crash reports, only frames from your app's executable are in-app. Frames from dynamic frameworks, such as Hermes, are no longer marked as your code, so some existing native crash issues may be grouped again once.







