React Native error tracking installation
- 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 LogLevel - 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 native Android and iOS exception capture
- No automatic source map uploads on React Native web
These features will be added in future releases. We recommend you stay up to date with the latest version of the PostHog React Native SDK.
- 8

