Skill 76 · Instrument Error Tracking
Subchapter 76.23
references/react-native.mdMarkdown8 KBView on GitHub
AI agents: this is one page from PostHog’s docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt (opens in a new tab)
1
Required
Install the PostHog React Native library and its dependencies:
npx expo install posthog-react-native expo-file-system expo-application expo-device expo-localizationyarn add posthog-react-native @react-native-async-storage/async-storage react-native-device-info react-native-localize
# for iOS
cd ios && pod installnpm i -s posthog-react-native @react-native-async-storage/async-storage react-native-device-info react-native-localize
# for iOS
cd ios && pod install2
Required
PostHog is most easily used via the PostHogProvider component. Wrap your app with the provider:
App.tsx
import { PostHogProvider } from 'posthog-react-native'
export function MyApp() {
return (
<PostHogProvider
apiKey="<ph_project_token>"
options={
3
Recommended
Once installed, PostHog will automatically start capturing events. You can also manually send events using the usePostHog hook:
Component.tsx
import { usePostHog } from 'posthog-react-native'
function MyComponent() {
const posthog = usePostHog()
const handlePress = () => {
4
Recommended
Client-side configuration only
Support for remote configuration in the error tracking settings (opens in a new tab) requires SDK version 4.35.0 or higher.
You can autocapture exceptions by configuring the errorTracking when setting up PostHog:
React Native
export const posthog = new PostHog('<ph_project_token>', {
errorTracking: {
5
Optional
You can use the PostHogErrorBoundary component to capture rendering errors thrown by components:
React Native
import { PostHogProvider, PostHogErrorBoundary } from 'posthog-react-native'
import { View, Text } from 'react-native'
const App = () => {
6
Optional
You can manually capture exceptions using the captureException method:
React Native
try {
// Your awesome code that may throw
someRiskyOperation();
} catch (error) {
posthog.captureException(error)
}This is helpful if you’ve built your own error handling logic or want to capture exceptions that are handled by your application code.
7
Optional
We currently don’t support the following features:
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.
Recommended
Confirm events are being sent to PostHog
Before proceeding, let’s make sure exception events are being captured and sent to PostHog. You should see events appear in the activity feed.

8
Required
Great, you’re capturing exceptions! The next step is to upload source maps (for JavaScript stack traces) and native symbols (for native iOS/Android crash symbolication) so PostHog can generate accurate stack traces.
Let’s continue to the next section.
The @posthog/react-native-plugin package supports CocoaPods, the hybrid CocoaPods and Swift Package Manager path, and React Native’s full Swift Package Manager integration. PostHog verifies the full path with an iOS-only React Native 0.87.1 app and React Native Community CLI 20.2.0. This path requires @posthog/react-native-plugin 2.4.0 or later, Xcode 16 or later, and an iOS 15.1 or later app deployment target.
See iOS dependency paths for the React Native native plugin (opens in a new tab) for the requirements and setup steps. This verification does not cover Expo or other React Native versions. Use CocoaPods or the hybrid path unless you validate full Swift Package Manager for your configuration.
Ask PostHog AI
HelpfulCould be better
Configuration options:
| Option | Description |
|---|---|
uncaughtExceptions | Captures Uncaught exceptions (ReactNativeGlobal.ErrorUtils.setGlobalHandler) |
unhandledRejections | Captures Unhandled rejections (ReactNativeGlobal.onunhandledrejection) |
console | Captures console logs as errors according to the reported LogLevel |
nativeCrashes | Captures native iOS/Android crashes. Requires @posthog/react-native-plugin and uploaded native symbols (see below) |
Capturing native crashes
nativeCrashes captures native iOS and Android crashes that the JavaScript layer can’t see. Beyond the config above, it needs:
npx expo install @posthog/react-native-plugin (Expo) or npm i @posthog/react-native-plugin (bare React Native). If it’s missing, native capture is a no-op and your JS-level autocapture is unaffected.Duplicate errors with console capture
If you have both PostHogErrorBoundary and console capture enabled in your errorTracking config, render errors will be captured twice. This is because React logs all errors to the console by default. To avoid this, set console: [] on errorTracking.autocapture (for example, errorTracking: { autocapture: { console: [] } }) when using PostHogErrorBoundary.
Dev mode behavior
In 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.