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.
Install the PostHog React Native library and its dependencies: PostHog is most easily used via the Once installed, PostHog will automatically start capturing events. You can also manually send events using the PostHog provides hooks to make it easy to use feature flags in your React Native app. Use For multivariate flags, use Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.Install the package
RequiredConfigure PostHog
RequiredPostHogProvider component. Wrap your app with the provider:Send events
RecommendedusePostHog hook:Use feature flags
RequireduseFeatureFlagEnabled for boolean flags:Multivariate flags
getFeatureFlag:Running experiments
Optional
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: