Guides and Surveys React Native SDK
Amplitude's Guides and Surveys SDK enables you to deploy Guides and Surveys on your website or application.
Requirements
The Guides and Surveys React Native SDK requires:
- The "new" React Native architecture.
- React Native 0.79.2+.
- Android Gradle 8.7.2+.
- Gradle 8+.
- iOS 15+.
- Swift 5.9+.
Installation
Install the SDK
Install the Guides and Surveys React Native SDK as a package with npm or Yarn.
npm install @amplitude/plugin-engagement-react-native
npm install @react-native-async-storage/async-storage
Async storage
Explicitly adding @react-native-async-storage/async-storage ensures the native module links correctly, since the engagement native module uses it.
Run pod install in the ios directory.
cd ios
bundle exec pod install
Initialize the SDK
//index.js
import { Linking } from "react-native";
import { init, add } from "@amplitude/analytics-react-native";
import {
getPlugin,
handleURL,
} from "@amplitude/plugin-engagement-react-native";
init("<<< YOUR API KEY HERE >>>");
add(getPlugin());
Linking.getInitialURL().then(async (url) => {
if (url) {
const didHandleURL = await handleURL(url);
if (didHandleURL) {
return;
}
// Handle a non-Amplitude SDK URL
}
});
Linking.addEventListener("url", async ({ url }) => {
const didHandleURL = await handleURL(url);
if (didHandleURL) {
return;
}
// Handle a non-Amplitude SDK URL
});
Amplitude server zone
The SDK automatically uses the serverZone that initializes @amplitude/analytics-react-native. Refer to Configure the SDK. You don't need to pass serverZone in the options argument to init.
Configuration options
| Parameter | Type | Description |
|---|---|---|
apiKey | string | Required. API key of the Amplitude project you want to use. |
options.serverUrl | string | Optional. Sets a custom server URL for API requests. Use this option for proxy setups. Default: https://gs.amplitude.com (US) or https://gs.eu.amplitude.com (EU). |
options.cdnUrl | string | Optional. Sets a custom CDN URL for static assets. Use this option for proxy setups. Default: https://cdn.amplitude.com (US) or https://cdn.eu.amplitude.com (EU). |
options.mediaUrl | string | Optional. Sets a custom URL for proxying nudge images. Use this option for proxy setups when firewalls block images. Default: https://engagement-static.amplitude.com (US) or https://engagement-static.eu.amplitude.com (EU). |
options.logLevel | LogLevel.None or LogLevel.Error or LogLevel.Warn or LogLevel.Verbose or LogLevel.Debug. | Optional. Sets the log level. Default: LogLevel.Warn. |
options.locale | string | Optional. Sets the locale for localization. Defaults to the device's system language (for example, en). Note that the default is a language code only, not a full locale identifier like en-US. |
Use the same API key for Guides & Surveys and Analytics
To avoid analytics mismatches and ensure accurate data collection, use the same API key for both Guides & Surveys and your Analytics SDK. Both should reference the same Amplitude project. Using different API keys can cause:
- The SDK to fetch guides and surveys from the wrong project.
- Analytics data to appear in different projects.
- Insights and survey responses to be incomplete or mismatched.
Make sure the API key you provide to Guides & Surveys matches the API key used to initialize your Amplitude Analytics SDK.
Boot the plugin
Booting the plugin (with a user ID) enables Guides and Surveys to be shown:
import { boot } from "@amplitude/plugin-engagement-react-native";
import {
track,
setDeviceId,
setUserId,
} from "@amplitude/analytics-react-native";
import { useEffect } from "react";
export default function App() {
useEffect(() => {
//
// setting the User ID in @amplitude/analytics-react-native
// --and-- passing it to boot() is necessary
//
setUserId("rn-test-user-1");
setDeviceId("test-device-1");
// boot(user_id?: string, device_id?: string, user_properties?: Object): void
boot(
"rn-test-user-1" /* user_id */,
"test-device-1" /* device_id */,
{} /* user_properties */,
);
}, []);
}
After you boot the plugin, installation is complete. While optional, Amplitude recommends that you set up URL handling for preview mode.
Add your application to project settings
After installing the SDK, add your React Native application to your Amplitude project settings so it appears as a platform option when you create guides and surveys.
To add your application:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the Guides and Surveys tab.
- In the App Management section, expand and click + Add App.
- Select React Native from the dropdown.
After you add your application, you can select it as a platform option when you create or edit guides and surveys for your React Native app users.
Set a minimum SDK version (when needed)
Mobile SDK versions 3.0.0 and later support Minimum SDK version. Use this setting as a safety control when you identify a critical issue in an older SDK release.
To configure a minimum SDK version:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the Guides and Surveys tab.
- In the App Management section, expand and click + Add App.
- Select React Native from the dropdown.
- Enter a value in Minimum SDK version.
When you set this value, Guides and Surveys compares the configured minimum with the SDK version in each app build:
- If an app build uses an older SDK version, the SDK doesn't initialize in that build.
- If an app build uses the same or newer SDK version, the SDK initializes as expected.
Use this setting to stop guides and surveys on known problematic SDK versions without rolling back your application release.
Example usage of minimum SDK version
Suppose app version 120 uses Guides and Surveys SDK 3.0.2, and app version 121 uses Guides and Surveys SDK 3.1.0 with a bug fix. If you set Minimum SDK version to 3.1.0:
- App version
120no longer loads Guides and Surveys. - App version
121continues to load Guides and Surveys.
Element targeting
Pin and tooltip guides require the SDK to target specific views on screen. The Engagement SDK uses the testID property on an element in the React Native DOM.
In the following example, use welcome-banner as the element targeting string in the Guides and Surveys dashboard.
import React from "react";
import { View, Text, StyleSheet } from "react-native";
/**
* A simple component with a testID that can be targeted
* by the Amplitude Guides & Surveys SDK.
*/
export default function WelcomeBanner() {
return (
<View
testID="welcome-banner" // Element targeting via testID
style={styles.banner}
>
<Text style={styles.bannerText}>Welcome to the App!</Text>
</View>
);
}
Simulate Guides and Surveys for preview
Preview guides and surveys directly in your application to view the same experience your users receive. Previewing makes it easier to iterate on copy, targeting rules, and trigger logic.
Deep linking required for preview
If your app doesn't have deep linking enabled, follow React Native's instructions to add support for deep linking. Previewing guides and surveys on a phone, tablet, or simulator requires this configuration.
Set up preview in Xcode (iOS)
Locate the mobile URL scheme
To locate the URL scheme:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the General tab.
- Find the URL scheme (mobile) field.
- Copy its value, for example,
amp-abcdefgh12345678.
Add the URL scheme in Xcode
- Open your iOS project in Xcode.
- In the Project navigator, select your app's target.
- On the Info tab, locate or add the URL Types section.
- Add a new URL type with the following values:
- URL identifier: Provide a descriptive name, like
AmplitudeURLScheme. - URL Schemes: Paste the value you copied from Amplitude, for example
amp-abc123.
- URL identifier: Provide a descriptive name, like
Set up preview in Android Studio (Android)
Locate the mobile URL scheme
To locate the URL scheme:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the General tab.
- Find the URL scheme (mobile) field.
- Copy its value, for example,
amp-abcdefgh12345678.
Add the URL scheme in Android Studio
Add the following intent filter to the main activity to your project's AndroidManifest.xml file:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Add your URL scheme from Amplitude Dashboard here -->
<!-- ex: android:scheme="amp-12345" -->
<data android:scheme="<your-unique-scheme-id>" />
</intent-filter>
</activity>
URL handling for preview links
The initialization code snippet handles URL handling for preview links. The relevant code is:
Linking.getInitialURL().then(async (url) => {
if (url) {
const didHandleURL = await handleURL(url);
if (didHandleURL) {
return;
}
// Handle a non-Amplitude SDK URL
}
});
Linking.addEventListener("url", async ({ url }) => {
const didHandleURL = await handleURL(url);
if (didHandleURL) {
return;
}
// Handle a non-Amplitude SDK URL
});
Super Debugger
When you scan a preview QR code from the Amplitude dashboard, a small blue Amplitude logo appears at the bottom of your screen. Tap it to open the Super Debugger panel.
The Super Debugger has two tabs: Details and Setup.
Details tab
The Details tab shows information about the guide or survey you're previewing and lets you inspect and control the preview session.
Guide / Survey: The name of the active guide or survey. Tap it to switch to a different guide or survey.
Details:
- Step: The current step number out of the total (for example, "1 of 3"). Tap the copy icon to copy the value.
- User: The user ID for the preview session. Tap the copy icon to copy it.
- Screen: The screen name the SDK currently reports. Tap the copy icon to copy it.
Debug: Shows whether the guide or survey passes each condition check. Each row expands to show details:
- Limits: Whether the guide or survey reached its display limit. Expand to review the configured limit.
- Trigger: Whether the guide or survey meets the trigger condition. Expand to review the trigger type, screen conditions, and pin target element (if applicable).
- Throttle: Whether the guide or survey meets the throttle condition. Expand to review the throttle setting. Toggle Ignore limits to bypass throttle limits during your preview session.
Advanced:
- Pin Debugging: Expand to enable Reposition pins every 5 seconds. The debugger periodically re-evaluates pin positions to help debug pin placement on dynamic layouts.
At the bottom of the panel:
- Restart Preview: Resets the guide or survey to its first step and restarts the preview.
- Close Preview: Exits preview mode and dismisses the Super Debugger.
Setup tab
The Setup tab shows SDK configuration and environment details for the current session.
SDK Versions: The version of the Engagement SDK installed in your app.
Installation:
- Type: The SDK installation method (for example, Plugin or standalone).
- Configuration: The number and type of custom configuration options applied.
User:
- User ID: The user ID passed to the SDK on boot.
- Properties: Any user properties set for the current session.
Event Flow: Confirms whether events are flowing correctly:
- Events flowing into Guides and Surveys SDK: Events from your analytics instance reach the Engagement SDK.
- Events flowing out of Guides and Surveys SDK: The Engagement SDK sends events to Amplitude.
Support
Tap the ? button to open the Support panel. From here you can:
- Open links to the SDK documentation and Guides and Surveys overview.
- File Bug Report: Submit a bug report directly from the debugger. Fill in steps to reproduce, expected results, and actual results, then tap Send.
Localization
The SDK defaults to the device's system language when you don't set the locale option at initialization. The default is a language code only (for example, en), not a full locale identifier like en-US.
To set a specific language, pass the locale option when you initialize the SDK:
import { init, add } from "@amplitude/analytics-react-native";
import { getPlugin } from "@amplitude/plugin-engagement-react-native";
init("YOUR_API_KEY");
add(
getPlugin({
locale: "es-ES",
}),
);
Known limitations
Tab bar element targeting
Pins and tooltips can't target tab bar items in navigation components (such as @react-navigation/bottom-tabs). Tab bars use native components that exist outside the standard React Native view hierarchy, which prevents the SDK from reliably locating and attaching guides to these elements.
Workaround
Use screen-based targeting or event-based triggers to show guides when users navigate to specific tabs. Do not pin directly to tab bar items.
Targeting animated elements and elements inside moving containers
Pins and tooltips can't target views or elements that are:
- Animated or in an animated container (they move around the screen).
- In a container that can move based on user interaction.
Note
Scrollviews usually work.
Workaround
Use screen-based targeting or event-based triggers to show guides, perhaps with a delay to ensure any animations have completed. Don't pin directly to elements in animated containers or containers that can move through user interaction.
Changelog
Go to the Mobile SDK changelog.
Was this helpful?