Skip to Content
React Native SDK

React Native SDK

Add live in-app micro-surveys to your React Native app. Like the iOS SDK, it fetches your published survey config, evaluates triggers on-device, and presents the right survey at the right time as a native bottom sheet or dialog, with no per-survey host code.

Beta. The React Native SDK is new. APIs below are stable for MVP; expect small changes as it’s hardened.

The package is @microsurveysai/react-native on npm. Source lives at MicroSurveysAI/microsurveys-react-native .

Requirements

  • React Native 0.72+ or Expo (works in Expo Go, as the package has no native code of its own).
  • Two common peer dependencies: @react-native-async-storage/async-storage and react-native-safe-area-context.
  • A project API key from the dashboard (ms_live_… / ms_test_…), the same key your iOS and web apps use.

Survey platform targeting uses the device: the SDK reports ios or android, so a survey targeted at iOS shows in your React Native app on iPhone too.

1. Install

npx expo install @microsurveysai/react-native @react-native-async-storage/async-storage react-native-safe-area-context

2. Create the SDK and wrap your app

// microsurveys.ts import { MicroSurveys } from "@microsurveysai/react-native"; export const ms = new MicroSurveys({ apiKey: "ms_live_xxx" });
// App.tsx import { MicroSurveysProvider } from "@microsurveysai/react-native"; import { ms } from "./microsurveys"; export default function App() { return ( <MicroSurveysProvider instance={ms}> <RootNavigator /> </MicroSurveysProvider> ); }

The provider starts the SDK on mount: it loads the cached config, fetches the latest, flushes any queued responses, and presents auto-triggered surveys over your app. If you don’t need the instance elsewhere, <MicroSurveysProvider apiKey="ms_live_xxx"> creates one for you.

3. Send events

Register the plugin on your existing Amplitude instance. Every event you already track, and the user’s identity, flow into the SDK; events pass through unmodified.

import { add, init } from "@amplitude/analytics-react-native"; import { ms } from "./microsurveys"; init("AMPLITUDE_API_KEY"); add(ms.amplitudePlugin());

Identity follows Amplitude: the user id (or device id) identifies the respondent, and properties set with identify() are used for audience targeting.

When an event satisfies a survey’s trigger (and the survey passes audience, sampling, and frequency rules), it presents itself after the configured delay. Calls made before the SDK has loaded its storage are queued, not dropped.

4. Identify the user (optional)

Not needed with Amplitude. Otherwise, attach a stable user id and properties to target audiences and keep frequency caps consistent across devices:

ms.identify("user_123", { plan: "pro", locale: "en-US" });

Without an id, the SDK uses a stable anonymous id persisted on the device.

Inline surveys

To show a specific survey inside a screen (e.g. a feedback screen) instead of as an overlay, use <MicroSurvey>:

import { MicroSurvey } from "@microsurveysai/react-native"; <MicroSurvey surveyId="svy_abc" onComplete={(result) => console.log(result)} />;

Inline surveys ignore triggers and platform targeting: rendering one is an explicit choice by you.

Configuration

new MicroSurveys({...}) accepts:

OptionDefaultDescription
apiKey—Your project’s API key.
apiBaseURLMicroSurveys APIOverride for self-hosted deployments.
refreshOnForegroundtrueWhen the app returns to the foreground, retry queued responses and refresh the config if it’s older than configTTLms.
configTTLms12 hoursHow long a cached config counts as fresh.
storage—A synchronous store (e.g. MMKV) to use instead of AsyncStorage.

<MicroSurveysProvider> accepts instance (or apiKey / apiBaseURL), autoStart (default true), and fontFamily.

Fonts

React Native can’t download fonts at runtime without a native module, so surveys use the system font by default. To match a dashboard theme font, register it in your app (e.g. with expo-font) and pass its family name:

<MicroSurveysProvider instance={ms} fontFamily="Inter">

How it works

  • On-device eligibility. The same rules as the iOS SDK: config is cached with an ETag, and triggers, audience, deterministic sampling and frequency caps are evaluated on the device, so a user lands in the same sample on every platform.
  • Offline-safe ingest. Impressions and responses are queued in AsyncStorage and sent with idempotency keys, so nothing is lost or double-counted.
  • Native look. Surveys present as a bottom sheet (drag the top to dismiss) or a centered dialog, follow light/dark mode, avoid the keyboard, and use your dashboard theme.

Troubleshooting

A survey isn’t showing. Confirm the survey is ACTIVE, targets this platform (ios / android), the event name in its trigger exactly matches what you track, and the user passes the audience/sampling rules. Frequency caps also apply per user.

  • Nothing on first launch. The config is fetched on start; a survey presents once the config has arrived and its trigger fires.
  • Required surveys. A survey marked non-dismissible hides the close button and ignores scrim taps, swipes and the Android back button.