Error Tracking React Native
PostHogOfficialCreated by PostHog
- Skill
- Tool integration
- Data and AI
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides guidance on implementing PostHog error tracking within React Native projects. It covers SDK installation, configuration best practices, and the integration of source maps to ensure stack traces are readable. The skill emphasizes non-intrusive implementation, recommending that developers maintain existing error handling logic while augmenting it with PostHog's capture capabilities. It also outlines how to leverage PostHog's broader platform features, such as automated issue assignment and alerting, to streamline debugging workflows.
What it does
- Guides the installation of the posthog-react-native SDK.
- Provides best practices for managing environment variables and project tokens.
- Explains how to upload source maps for readable stack traces.
- Details the use of manual capture for specific error boundaries.
- Outlines configuration for automated issue assignment and alerting.
- Describes how to monitor and search for issues within the PostHog dashboard.
When to use it
- When you need to track and monitor runtime errors in a React Native application.
- When you want to centralize error reporting and team-based issue triage.
- When you need to set up automated alerts for critical application crashes.
- When you are setting up a new React Native project and want to include observability from the start.
Advantages
- Maintains existing application error handling structures.
- Enables detailed debugging through unminified stack traces via source maps.
- Supports team collaboration through automated issue assignment rules.
- Provides flexible alerting options including Slack, Discord, and webhooks.
Usage examples
- “How do I initialize PostHog in my React Native app?”
- The agent will explain installing the posthog-react-native and react-native-svg packages, configuring environment variables, and wrapping your app with the PostHogProvider.
- “How can I make sure my error stack traces are readable?”
- The agent will provide instructions on generating and uploading source maps to PostHog so that minified production code can be mapped back to the original source.
- “How do I get notified when a specific error happens?”
- The agent will guide you through setting up alerting rules in the PostHog error tracking configuration, including filtering by exception type or message.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/posthog/error-tracking-react-native/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip error-tracking-react-native.zip -d .agents/skills
Documentation by PostHog
PostHog error tracking for React Native
This skill helps you add PostHog error tracking to React Native applications.
Reference files
references/react-native.md- React native error tracking installation - docsreferences/fingerprints.md- Fingerprints - docsreferences/alerts.md- Send error tracking alerts - docsreferences/monitoring.md- Monitor and search issues - docsreferences/assigning-issues.md- Assign issues to teammates - docsreferences/upload-source-maps.md- Upload source maps - docs
Consult the documentation for API details and framework-specific patterns.
Key principles
Environment variables: Always use environment variables for PostHog keys and host URLs. Never hardcode them.
Minimal changes: Add error tracking alongside existing error handling. Don't replace or restructure existing error handling code.
Autocapture first: Enable exception autocapture in the SDK initialization before adding manual captures.
Source maps: Upload source maps so stack traces resolve to original source code, not minified bundles.
Manual capture for boundaries: Use
captureException()at error boundaries and catch blocks for errors that don't propagate to the global handler.
Framework guidelines
posthog-react-native is the React Native SDK package name
Use react-native-config to load POSTHOG_PROJECT_TOKEN and POSTHOG_HOST from .env (variables are embedded at build time, not runtime)
react-native-svg is a required peer dependency of posthog-react-native (used by the surveys feature) and must be installed alongside it
Place PostHogProvider INSIDE NavigationContainer for React Navigation v7 compatibility
Files
- ATTRIBUTION.mdAdded by AutoGineer981 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md1.8 KiB
- references/alerts.md4.1 KiB
- references/assigning-issues.md5.5 KiB
- references/fingerprints.md3.4 KiB
- references/monitoring.md8.6 KiB
- references/react-native.md6.2 KiB
- references/upload-source-maps.md2.7 KiB
references/react-native.md
React Native error tracking installation - Docs
1
Install the package
Required
Install the PostHog React Native library and its dependencies:
PostHog AI
Expo
npx expo install posthog-react-native expo-file-system expo-application expo-device expo-localizationyarn
yarn add posthog-react-native @react-native-async-storage/async-storage react-native-device-info react-native-localize # for iOS cd ios && pod installnpm
npm i -s posthog-react-native @react-native-async-storage/async-storage react-native-device-info react-native-localize # for iOS cd ios && pod install2
Configure PostHog
Required
PostHog is most easily used via the
PostHogProvidercomponent. Wrap your app with the provider:App.tsx
PostHog AI
import { PostHogProvider } from 'posthog-react-native' export function MyApp() { return ( <PostHogProvider apiKey="<ph_project_token>" options={{ host: "https://us.i.posthog.com", }} > <RestOfApp /> </PostHogProvider> ) }3
Send events
Recommended
Once installed, PostHog will automatically start capturing events. You can also manually send events using the
usePostHoghook:Component.tsx
PostHog AI
import { usePostHog } from 'posthog-react-native' function MyComponent() { const posthog = usePostHog() const handlePress = () => { posthog.capture('button_pressed', { button_name: 'signup' }) } return <Button onPress={handlePress} title="Sign Up" /> }4
Set up exception autocapture
Recommended
Client-side configuration only
Support 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 Native
PostHog AI
export const posthog = new PostHog('<ph_project_token>', { errorTracking: { autocapture: { uncaughtExceptions: true, unhandledRejections: true, console: ['error', 'warn'], }, }, })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 5
Set up error boundaries
Optional
You can use the
PostHogErrorBoundarycomponent to capture rendering errors thrown by components:React Native
PostHog AI
import { PostHogProvider, PostHogErrorBoundary } from 'posthog-react-native' import { View, Text } from 'react-native' const App = () => { return ( <PostHogProvider apiKey="<ph_project_token>"> <PostHogErrorBoundary fallback={YourFallbackComponent} additionalProperties={{ screen: "home" }} > <YourApp /> </PostHogErrorBoundary> </PostHogProvider> ) } const YourFallbackComponent = ({ error, componentStack }) => { return ( <View> <Text>Something went wrong!</Text> <Text>{error instanceof Error ? error.message : String(error)}</Text> </View> ) }Duplicate errors with console capture
If 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 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.
6
Manually capture exceptions
Optional
You can manually capture exceptions using the
captureExceptionmethod:React Native
PostHog AI
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
Future features
Optional
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. We recommend you stay up to date with the latest version of the PostHog React Native SDK.
Verify error tracking
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.
Image: Activity feed with eventsImage: Activity feed with events
8
Upload source maps
Required
Great, you're capturing exceptions! If you serve minified bundles, the next step is to upload source maps to generate accurate stack traces.
Let's continue to the next section.
Community questions
Ask a question
Was this page useful?
HelpfulCould be better
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- PostHog
- Publisher
- PostHog (Official)
- Source
- PostHog/skills · skills/posthog/error-tracking/skills/react-native · commit a5d30e7
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Also distributed in
- PostHog/skills
AutoGineer is not affiliated with or endorsed by PostHog.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download error-tracking-react-native.zip