Get started with the React Native SDK

For React Native developers10 minBeginner

This guide installs the React Native SDK (@amplitude/analytics-react-native), initializes it, and sends one custom event to Amplitude. Each step lists the problems that commonly break that step, so you can fix each problem where it happens. For the full option list, go to Configuration options. For changes between versions, go to the React Native SDK release notes.

The React Native SDK is the analytics-only package. If you also need Session Replay, Feature Experiment, or Guides and Surveys, install the Unified SDK for React Native (@amplitude/unified-react-native) instead. It includes this SDK, so don't install both as direct dependencies.

Prerequisites

  • An Amplitude project and its API key. Find the key in Settings > Projects > your project > General.
  • The data center your organization uses: US (default) or EU.
  • A React Native app for iOS, Android, or the web (react-native-web). React Native doesn't keep backward compatibility between releases, so check the React Native CLI compatibility list before you upgrade.
  • React Native 0.68 or later, Gradle 7.5.1 or later, and Android Gradle Plugin 7.2.1 or later. These are the minimums SDK 1.4.0 and later build with. Amplitude support covers the latest React Native version only. For older SDK versions, go to Platform support.
  • iOS 12.0 or later, and Android API level 21 or later. These are the minimums the SDK's native modules declare. Your React Native version can require higher ones.

Install the SDK

The SDK stores identity and unsent events in @react-native-async-storage/async-storage, so install that package too. To use a different storage backend, go to Store data somewhere other than AsyncStorage.

bash
npm install @amplitude/analytics-react-native @react-native-async-storage/async-storage
cd ios && pod install

Then import the package:

ts
import * as amplitude from "@amplitude/analytics-react-native";

The SDK has native modules for iOS and Android. If you ship over-the-air (OTA) updates, for example with Expo EAS Update, publish a new native build when you upgrade across a release that changed native code. Go to Platform support for those releases.

Fix installation problems

Initialize the SDK

Call init() once, as early as possible, for example at the top of your app's entry file. The SDK queues calls you make before init() finishes and runs them in order afterward.

ts
amplitude.init("AMPLITUDE_API_KEY");

Pass a user ID as the second argument when you already know it. Pass options as the third argument. To pass options without a user ID, set the second argument to undefined:

ts
amplitude.init("AMPLITUDE_API_KEY", "user-12345", {
  autocapture: true,
});

amplitude.init("AMPLITUDE_API_KEY", undefined, {
  autocapture: true,
});

If your project uses the EU data center, set serverZone:

ts
amplitude.init("AMPLITUDE_API_KEY", undefined, {
  serverZone: "EU",
});

Autocapture is off by default. autocapture: true turns on sessions, application lifecycles, screen views, element interactions, frustration interactions, and network tracking. For each feature, go to Autocapture.

Fix initialization problems

Send a first event

Track one custom event and wait for the upload result. track() returns an object whose promise resolves after the SDK finishes the upload attempt.

ts
const result = await amplitude.track("Sign Up Clicked", {
  plan: "starter",
}).promise;

console.log(result.code, result.message);
// 200 "Event tracked successfully"

The SDK uploads queued events about one second after the first one enters the queue, in requests of up to 30 events, so expect about one second of delay.

Fix upload problems

Confirm the event in Amplitude

  1. In Amplitude, open User Lookup and search for the user ID you passed, or for the device ID from amplitude.getDeviceId().
  2. Open the Activity tab and turn on Live event updates.
  3. Confirm that Sign Up Clicked appears with the plan property.

If the event doesn't appear within a minute, follow Verify events. That page walks through each stage between track() and Amplitude's servers.

Next steps

Was this helpful?

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

On this page