React Native surveys installation
Contents
- 1
Add PostHog to your app
RequiredUsing surveys requires PostHog's React Native SDK version >= 4.5.0. It's recommended to always use the latest version.
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
Install surveys dependencies
RequiredTerminal - 3
Add the surveys provider
RequiredAdd
PostHogSurveyProviderto your app anywhere insidePostHogProvider. This component fetches surveys. It also acts as the root for where popover surveys are rendered.TypeScriptIf you're not using the
PostHogProvider, addPostHogSurveyProviderto your app anywhere inside your app root component.TypeScriptYou can also pass your
clientinstance to thePostHogSurveyProvider.TypeScript
Supported Features
| Feature | Support |
|---|---|
| Questions | |
| All question types | ✅ |
| Multi-question surveys | ✅ |
| Confirmation message | ✅ |
| Feedback button presentation | ❌ |
| Conditional questions | ✅ >= v4.5.0 |
| Customization / Appearance | |
| Set colors in PostHog dashboard | ✅ Or override with your app theme |
| Shuffle questions | ❌ |
| PostHog branding | ❌ |
| Delay popup after screen view | ❌ |
| Position config | ❌ Always bottom center |
| HTML content | ❌ |
| Display conditions | |
| Feature flag & property targeting | ✅ |
| Screen targeting | ❌ |
| Device type targeting | ✅ |
| CSS selector matches | ❌ |
| Survey wait period | ❌ |
| Event triggers | ✅ |
| Action triggers | ❌ |
| Partial responses | ❌ |
Troubleshooting
- Update your SDK.
- Run a clean build if you experience issues.
- For surveys not shown, be sure to set up the surveys provider.
- If you have enabled surveys using feature flags, the flags are evaluated on the device once the PostHog SDK starts as early as possible. The SDK might be using the cached flags from the previous SDK start. If you have changed the flag or its condition, kill and reopen the app to force a new SDK start at least once.
- This will also happen in production, and you might experience some delay for the new flag/conditions to take effect on your users.
- Survey feature flag evaluation does not capture
$feature_flag_calledevents, so theUsagetab on the feature flag page won't show anything.