React Native product analytics installation
Contents
Our React Native library enables you to integrate PostHog with your React Native project. For Expo projects, there are no mobile native dependencies outside of supported Expo packages.
- 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
Next steps
RecommendedNow that you're capturing events, continue with the resources below to learn what else Product Analytics enables within the PostHog platform.
Resource Description Capturing events Learn how to capture custom events beyond autocapture Identifying users Associate events with specific users Creating insights Build trends, funnels, and retention charts Group analytics Track events at the company or account level
React Native Web and macOS
If you're using React Native Web or React Native macOS, don't use expo-file-system since Web and macOS targets aren't supported. Use @react-native-async-storage/async-storage instead.
Without the PostHogProvider
If you prefer not to use the provider, initialize PostHog in its own file and import the instance:
Then access PostHog by importing your instance:
You can also use this instance with the PostHogProvider: