React Native error tracking installation
Contents
We 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.
- 1
Install PostHog React Native SDK
RequiredHermes engineReact Native error tracking is supported supported for Android and iOS apps compiled with the Hermes engine enabled.
A minimum SDK version of 4.12.0 is required, but we recommend keeping up with the latest SDK version to ensure you have all of error tracking's features.
Our React Native enables you to integrate PostHog with your React Native project. For React Native projects built with Expo, there are no mobile native dependencies outside of supported Expo packages.
To install, add the
posthog-react-nativepackage to your project as well as the required peer dependencies.Expo apps
TerminalReact Native apps
TerminalReact Native Web and macOS
If you're using React Native Web or React Native macOS, do not use the expo-file-system package since the Web and macOS targets aren't supported, use the @react-native-async-storage/async-storage package instead.
Configuration
With the PosthogProvider
The recommended way to set up PostHog for React Native is to use the
PostHogProvider. This utilizes the Context API to pass the PostHog client around, and enables autocapture.To set up
PostHogProvider, add it to yourApp.jsorApp.tsfile:App.jsThen you can access PostHog using the
usePostHog()hook:React NativeWithout the PosthogProvider
If you prefer not to use the provider, you can initialize PostHog in its own file and import the instance from there:
posthog.tsThen you can access PostHog by importing your instance:
React NativeYou can even use this instance with the PostHogProvider:
React Native - 2
Set up exception autocapture
RecommendedThis configuration is client-side only. Support for remote configuration in the error tracking settings will be added in a future release.
You can autocapture exceptions by configuring the
errorTrackingwhen setting up PostHog:React NativeConfiguration options:
uncaughtExceptions: Captures Uncaught exceptions (ReactNativeGlobal.ErrorUtils.setGlobalHandler)unhandledRejections: Captures Unhandled rejections (ReactNativeGlobal.onunhandledrejection)console: Captures console logs as errors according to the reportedLogLevel.
- 3
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.
- 5

