React Native SDK reference

This reference documents every public export of @amplitude/analytics-react-native and every option you can pass to init(), verified against version 1.13.0. For options, go to Configuration options. To find the release that added a feature, go to the React Native SDK release notes.

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

The top-level functions act on a default instance. Each instance from createInstance() has the same methods.

Return values

Methods that do asynchronous work return AmplitudeReturn<T>, an object with one property, promise. Await promise, not the return value itself.

ts
const result = await amplitude.track("Song Played").promise; // correct
const wrapper = await amplitude.track("Song Played"); // returns { promise }, not a Result

Tracking methods resolve to a Result after the upload attempt finishes:

For every code and message, go to Read the upload result.

Calls made before init() completes wait in a queue and run in order afterward. Their promises resolve after init() finishes and the upload completes.

Setup

init

Initializes the instance. Call it once per instance.

ts
init(apiKey: string, userId?: string, options?: ReactNativeOptions): AmplitudeReturn<void>

init() has no (apiKey, options) form. An object passed second becomes the user ID.

promise resolves after the SDK restores identity, installs plugins, and runs queued calls.

ts
await amplitude.init("AMPLITUDE_API_KEY", "user-12345", {
  serverZone: "EU",
}).promise;

createInstance

Creates an independent instance with its own configuration, identity, queue, and plugins. Use it to send data to more than one project.

ts
createInstance(): ReactNativeClient
ts
const secondary = amplitude.createInstance();
secondary.init("OTHER_API_KEY", undefined, { instanceName: "secondary" });

add

Adds a plugin. Go to Plugin.

ts
add(plugin: Plugin): AmplitudeReturn<void>
ts
amplitude.add({
  name: "add-app-flavor",
  execute: async (event) => {
    event.event_properties = { ...event.event_properties, flavor: "beta" };
    return event;
  },
});

remove

Removes a plugin by name and runs its teardown().

ts
remove(pluginName: string): AmplitudeReturn<void>
ts
amplitude.remove("add-app-flavor");

flush

Sends every queued event now. A manual flush doesn't retry failures.

ts
flush(): AmplitudeReturn<void>
ts
await amplitude.flush().promise;

Tracking

track

Tracks an event. logEvent() is an alias.

ts
track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): AmplitudeReturn<Result>
ts
amplitude.track("Song Played", { title: "Happy Birthday" });

identify

Sends user property operations as an $identify event. Go to Identify.

ts
identify(identify: IIdentify, eventOptions?: EventOptions): AmplitudeReturn<Result>

If eventOptions sets user_id or device_id, the SDK also stores it as the current identity.

ts
amplitude.identify(new amplitude.Identify().set("plan", "premium"));

setGroup

Assigns the current user to one or more groups.

ts
setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): AmplitudeReturn<Result>
ts
amplitude.setGroup("orgId", "15");

groupIdentify

Sets properties on a group.

ts
groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions): AmplitudeReturn<Result>
ts
amplitude.groupIdentify("orgId", "15", new amplitude.Identify().set("plan", "enterprise"));

revenue

Sends a revenue_amount event. Go to Revenue.

ts
revenue(revenue: IRevenue, eventOptions?: EventOptions): AmplitudeReturn<Result>
ts
amplitude.revenue(new amplitude.Revenue().setProductId("premium").setPrice(3.99));

trackScreenView

Sends [Amplitude] Screen Viewed with [Amplitude] Screen Name set to screenName, and remembers the screen name for element and frustration events. Does nothing when autocapture.screenViews is false. Requires 1.6.6 or later.

ts
trackScreenView(screenName: string, eventProperties?: Record<string, any>, eventOptions?: EventOptions): AmplitudeReturn<Result | undefined>
ts
amplitude.trackScreenView("Home", { tab: "feed" });

trackScreenViewOnNavigationStateChange

Finds the focused screen in a React Navigation state and calls trackScreenView() with its name. Skips the call when the focused screen hasn't changed since the last call. Requires 1.6.6 or later.

ts
trackScreenViewOnNavigationStateChange(navigationState: NavigationState | undefined, eventProperties?: Record<string, any>, eventOptions?: EventOptions): AmplitudeReturn<Result | undefined>
tsx
<NavigationContainer onStateChange={amplitude.trackScreenViewOnNavigationStateChange} />

ampCapture

Wraps an event handler so each call sends [Amplitude] Element Interacted when autocapture.elementInteractions is on, and feeds frustration detection. Returns a function with the same signature as func. Nested ampCapture calls report once. Requires 1.6.8 or later.

ts
ampCapture<Args extends unknown[], Return>(func: (...args: Args) => Return, properties: AmpCaptureProperties): (...args: Args) => Return

All properties are optional strings. Rage clicks need action: "Press", and error clicks need "Press" or "LongPress".

tsx
<Pressable onPress={amplitude.ampCapture(onBuy, { action: "Press", testID: "buy" })} />

createNetworkRequestEvent

Builds a [Amplitude] Network Request event from request data you collected yourself, for example from a native networking library. Pass the result to track(). It doesn't apply network tracking rules or mask data, so remove sensitive values first. Requires 1.13.0 or later.

ts
createNetworkRequestEvent(properties: NetworkRequestEventProperties): BaseEvent | undefined

It returns undefined, and logs an error, when url or method is empty, or when a time is negative or not finite.

ts
const event = amplitude.createNetworkRequestEvent({
  url: "https://api.example.com/orders?id=1",
  method: "POST",
  startTime: Date.now() - 350,
  duration: 350,
  statusCode: 503,
});

if (event) amplitude.track(event);

Identity

getUserId and setUserId

Reads or sets the user ID that the SDK attaches to every event. Pass undefined to clear it.

ts
getUserId(): string | undefined
setUserId(userId: string | undefined): void
ts
amplitude.setUserId("user-12345");

getDeviceId and setDeviceId

Reads or sets the device ID.

ts
getDeviceId(): string | undefined
setDeviceId(deviceId: string): void
ts
amplitude.setDeviceId("8d8a2e3c-2b6f-4f7e-9c1e-3a5b0c6d7e8f");

reset

Clears the user ID and sets a new random device ID. The session continues.

ts
reset(): void
ts
amplitude.reset();

Sessions

getSessionId and setSessionId

Reads the session ID, or starts a new session with the ID you pass. After setSessionId(), the session doesn't time out until you call it again or the app restarts.

ts
getSessionId(): number | undefined
setSessionId(sessionId: number): void
ts
amplitude.setSessionId(Date.now());

extendSession

Records activity without sending an event, so the session's timeout starts over.

ts
extendSession(): void

Privacy

setOptOut

Stops (true) or resumes (false) tracking. The SDK stores the setting with identity.

ts
setOptOut(optOut: boolean): void
ts
amplitude.setOptOut(true);

Identify

Identify collects user property operations for identify() and groupIdentify(). Each method returns the object, so you can chain calls. Use one operation per property per object: the SDK keeps the first operation for a property and ignores the rest.

ts
const identifyEvent = new amplitude.Identify()
  .set("plan", "premium")
  .add("login_count", 1);

Revenue

Revenue describes a purchase for revenue(). Each setter returns the object.

ts
const purchase = new amplitude.Revenue()
  .setProductId("com.company.premium")
  .setPrice(3.99)
  .setQuantity(3);

Plugin

A plugin is an object the SDK runs for every event. Pass it to add().

The Plugin type also declares onSessionIdChanged() and onReset(), but the React Native SDK never calls them.

For each event, the SDK runs every before plugin, then every enrichment plugin, then every destination plugin. Plugins of the same type run in the order you added them. Use the string types; the SDK doesn't export a PluginType enum.

ts
const lowercaseUserId: amplitude.Types.BeforePlugin = {
  name: "lowercase-user-id",
  type: "before",
  execute: async (event) => {
    if (event.user_id) event.user_id = event.user_id.toLowerCase();
    return event;
  },
};

amplitude.add(lowercaseUserId);

Storage

storageProvider and cookieStorage accept any object that implements Storage<T>. Every method is async.

Types

amplitude.Types exports TypeScript types and constants, including:

ServerZone and LogLevel are the only runtime values. The rest are TypeScript types, so they're undefined at runtime. Types doesn't include OfflineDisabled. To turn off offline detection, pass offline: null.

Configuration options

Pass these in the options argument of init(). Many options exist for react-native-web and do nothing on iOS or Android. Web-only options lists those options.

General options

The options type also accepts identify, but the React Native SDK doesn't apply it. Call identify() after init() instead.

Identity and session options

Data collection options

trackingOptions

Each option controls one event field. Set an option to false to omit the field.

If you turn on country, the SDK sends the device's country, which stops Amplitude from filling region, city, and DMA from the IP address.

Autocapture options

Pass autocapture: true to turn on every option in this table, or an object to choose. Options you leave out of an object are off.

NetworkTrackingOptions

NetworkCaptureRule

BodyCaptureRule

Safe headers

With requestHeaders: true or responseHeaders: true, the SDK records only these headers, so it doesn't capture credentials:

access-control-allow-origin, access-control-allow-credentials, access-control-expose-headers, access-control-max-age, access-control-allow-methods, access-control-allow-headers, accept-patch, accept-ranges, age, allow, alt-svc, cache-control, connection, content-disposition, content-encoding, content-language, content-length, content-location, content-md5, content-range, content-type, date, delta-base, etag, expires, im, last-modified, link, location, permanent, p3p, pragma, proxy-authenticate, public-key-pins, retry-after, server, status, strict-transport-security, trailer, transfer-encoding, tk, upgrade, vary, via, warning, www-authenticate, x-b3-traceid, x-frame-options.

Web-only options

These options apply only on react-native-web, where the SDK stores identity in a cookie.

Autocaptured event properties

Application events

Element interaction properties

[Amplitude] Element Interacted, [Amplitude] Rage Click, and [Amplitude] Error Click include these properties when the values exist:

Rage click properties

Error click properties

Network request properties

Platform support

The SDK supports iOS, Android, and react-native-web. It doesn't run in Expo Go. Its native modules declare iOS 12.0 and Android API level 21 as minimums.

These releases changed the SDK's iOS or Android code or build files: 1.3.0, 1.3.4, 1.3.6, 1.4.0, 1.4.1, 1.4.2, 1.4.11, 1.4.14, 1.5.52, 1.6.0, 1.6.5, 1.6.8, and 1.9.0. If you deliver updates over the air, ship a new native build when you upgrade across one of them. For each release, go to the SDK releases on GitHub.

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