React Native SDK · Preview
API reference
Every planned method of the RTN React Native SDK with its signature and behavior.
Preview: planned API
The React Native SDK is in development and not published yet. This page describes the API we are building so you can plan your integration. Package names, signatures and defaults may still change before the first release.
Public methods never throw. Invalid input is ignored and reported when debug is on. Method names match the Web SDK wherever the platform allows.
Setup
RTN.initialize(writeKey: string, options?: RTNOptions): Promise<void>
Starts the SDK. Call it once at launch.
RTN.version: string
The SDK version, for example 0.1.0.
Configuration
| Option | Default | Description |
|---|---|---|
consent | 'granted' | Initial analytics decision: 'granted', 'denied' or 'pending'. |
trackLifecycleEvents | true | Sends app_installed, app_updated, app_opened and app_backgrounded. |
trackDeepLinks | true | Sends deep_link_opened for links received by the native layer. |
collectAdvertisingId | false | Reads the platform advertising ID under the native consent rules. |
childDirected | false | Disables advertising identifiers and probabilistic attribution. |
flushAt | 20 | Sends a batch once this many events are queued. |
flushIntervalMs | 30000 | Sends queued events at least this often. |
debug | false | Logs dropped calls and validation problems to the Metro console. |
Consent
RTN.setConsent(state: 'granted' | 'denied' | 'pending'): Promise<void>
Sets the analytics decision to granted, denied or pending.
RTN.setConsentPurpose(purpose: ConsentPurpose, state: ConsentState): Promise<void> / RTN.getConsentPurpose(purpose: ConsentPurpose): Promise<ConsentState>
Manages a purpose-level decision. See Consent and privacy for purposes.
RTN.pause(): Promise<void> / RTN.resume(): Promise<void>
Stops and restarts collection and delivery without deleting identities or queued events. Calls made while paused are dropped.
Identity
RTN.identify(userId: string, traits?: Traits): Promise<void> / RTN.identify(traits: Traits): Promise<void>
Associates events with a known customer. For a guest without a customer ID, pass only traits with email or phone.
RTN.reset(): Promise<void>
Clears the known customer and starts a new anonymous identity. Call it at sign-out.
RTN.getAnonymousId(): Promise<string | null> / RTN.getInstallId(): Promise<string | null>
The device anonymous ID and the install ID assigned by RTN, or null without consent.
Events
RTN.track(event: string, properties?: Record<string, unknown>): void
Records a custom event. event must be lowercase snake_case.
RTN.screen(name: string, properties?: Record<string, unknown>): void
Records a screen_viewed event with screen_name.
RTN.register(properties: Record<string, unknown>): void / RTN.unregister(key: string): void
Adds or removes properties attached to every following event.
Ecommerce helpers
RTN.productViewed(product: Product): voidRTN.productAddedToCart(product: CartProduct): voidRTN.productRemovedFromCart(product: CartProduct): voidRTN.cartViewed(cart: Cart): voidRTN.checkoutStarted(cart: Cart): voidRTN.orderCompleted(order: Order): voidRTN.signedUp(method?: string): voidRTN.loggedIn(method?: string): voidRTN.searched(query: string): void
See Events and identity and the Web SDK Ecommerce Events page for fields.
Attribution and deep links
RTN.getAttribution(): Promise<Attribution | null>
Returns the local attribution snapshot, or null without consent.
RTN.waitForAttribution(options?: { timeoutMs?: number }): Promise<Attribution | null>
Resolves with server-confirmed install attribution, or with the local snapshot after the timeout.
RTN.handleDeepLink(url: string): Promise<boolean>
Records deep_link_opened for an incoming link and forwards it to onDeepLink listeners. Returns whether the link was handled.
RTN.onDeepLink(listener: (link: DeepLink) => void): () => void
Registers a listener for direct and deferred deep links. Unsubscribe when the listener is no longer needed.
Push
RTN.setPushToken(token: string | null): Promise<void>
Registers the device's Firebase Cloud Messaging token so flows can send it app pushes (POST /v1/mobile/push-tokens). Call it on every app start and whenever Firebase refreshes the token; pass null when the user turns notifications off. Add the project's Firebase service account key under Flows → Channels in the dashboard. Use the token from @react-native-firebase/messaging (getToken() and onTokenRefresh).
RTN.trackPushOpened(data: Record<string, unknown>): string | null
Records push_opened for a notification RTN sent and returns the link it should open. RTN pushes carry rtn_message_id and url in their data payload; url is a tracked link, so opening it also counts the tap as a click in flow reports.
Delivery
RTN.flush(): Promise<void>
Immediately attempts to send queued events.
Platform-specific
RTN.requestTrackingAuthorization(): Promise<'authorized' | 'denied' | 'restricted' | 'not_determined'>
Shows the App Tracking Transparency prompt on iOS. Resolves authorized immediately on Android.
useRTNScreenTracking(navigationRef): () => void
React Navigation helper that returns an onStateChange handler sending screen_viewed.