Skip to content
Docs menu · React Native SDK

Reference

React Native SDK Reference

Options, functions and components of @anyreplay/react-native: init, AnyReplay, trackNavigation, screen, consent, identify, flush, stop and getSessionId.

Reference for @anyreplay/react-native 0.3.0. The package has no native code; peer dependencies are react 18 or later and react-native 0.72 or later, and the screen is recorded only on the New Architecture (Fabric), on by default from React Native 0.76 and Expo SDK 52. On the old architecture taps, screen names and events are still recorded.

Options

Passed to init(options).
OptionTypeDefaultDescription
projectKeystringRequiredPublic key from your project.
ingestUrlstringhttps://in.anyreplay.comChange only for a self-hosted install.
sampleRatenumber1Share of visitors recorded, 0–1, decided once per visitor.
snapshotIntervalMsnumber500How often the screen is read. The main cost lever: slower is cheaper and coarser. Values below 100 are rejected.
maskAllInputsbooleantrueMasks every TextInput. On by default, as in the browser SDK; false records what a person types. Secure fields, and fields whose textContentType, autoComplete, keyboardType, label, placeholder or testID names a password, a one-time code or a payment instrument, are masked whatever this says — as is any value shaped like a card number, or like the first seven or more digits of one. With false, a card number inside longer text keeps the field recorded and has its digits after the sixth hidden. Only an explicit false turns it off.
maskAllTypingbooleanfalseMasks every TextInput whatever maskAllInputs says. A screen has no contenteditable, so unlike on the web it adds no new elements — what it adds is that masking cannot be turned off elsewhere in your configuration.
maskTestIDstring'ar-mask'Elements whose testID contains this are masked, with everything inside them.
maskImagesbooleanfalseRecord no image URLs; images replay as masked boxes.
requireConsentbooleanfalseRecord nothing, and write nothing to storage, until consent(true).
maxEventsPerChunknumber200Send a chunk when this many events are buffered.
flushIntervalMsnumber5000Send a chunk at least this often, in milliseconds.
maxConsecutiveFailuresnumber5, ignoredDeprecated and ignored since 0.2.0, which never stops for a failed delivery (0.1.4 stopped after five in a row): it waits 2 s doubling to a minute, never less than a Retry-After asks, and tries again at once when the app comes back to the foreground. Still accepted, so code that sets it keeps compiling.
maxBufferedEventsnumber2000Events kept while offline before the oldest are dropped. When what is dropped was part of the screen, the next tick sends the whole screen again.
recordErrorsbooleantrueRecord uncaught errors through ErrorUtils.setGlobalHandler, with their stacks, and whether React Native called them fatal. Your own handler — the red screen, a crash reporter — is always called afterwards and never replaced. At most 100 per session.
recordConsolebooleantrueRecord console.error and console.warn. log, info and debug are never recorded at any setting. At most 200 per session.
storageKeyValueStoreIn memoryAny object with async getItem(key) and setItem(key, value), such as AsyncStorage. Lets sessions resume and sampling stay stable across launches. removeItem, when present, is what consent(false) uses to forget the ids; without it they are emptied.
appIdstringNoneYour bundle id (iOS) or package name (Android), such as com.example.shop. An app has no web origin, so a project with allowed domains refuses it unless this id is on the project's Allowed apps. A filter rather than a secret. Since 0.2.0.
appVersionstringNoneYour app's version as people see it, at most 40 characters, shown with each session. React Native cannot read it without a native module, so pass it in — from expo-application, for example. Since 0.2.0.
debugbooleanfalseLog warnings: unmounted <AnyReplay>, refused requests. The old-architecture warning is logged either way.

Functions

FunctionDescription
init(options)Starts recording, or waits for consent. Returns Promise<RecorderHandle | null> — null if the options were invalid, logged as a warning instead of crashing the app. A second call returns the existing recorder.
consent(granted)true starts a recorder waiting for consent; false removes the stored ids and stops a recording. Safe to call before init has finished: the decision is applied the moment it does, and a false given before recording started leaves it waiting, so a later true on the same launch still starts it.
identify({ userId?, email? })Attaches an identity to the session. Best-effort. Called before init has finished, or while waiting for consent, the traits are held and sent once there is a session.
screen(name)Records a screen change: a marker, a page view and a fresh snapshot. A name given before recording starts — before init has finished, or while waiting for consent — is remembered, and the recording opens on that screen, counted once. (0.1.4 ignored it unless recording.)
track(name, properties?)Tags this moment, exactly as in the browser SDK: name 1–64 characters of [A-Za-z0-9_.:-], properties a plain JSON object ≤ 4 KB. Never throws, and a call made before recording starts is held and sent when it does. See custom events.
trackError(error)Records an error you caught yourself. Uncaught ones are recorded on their own; use this for the handled ones you still want in the replay, and for a rejection your own tracker saw — React Native fires no unhandledrejection event for the recorder to listen to.
trackNavigation(container)Follows a React Navigation container (or anything with getCurrentRoute and addListener('state')) and calls screen on each new route name. Returns a function that stops following.
flush()Sends buffered events now. Also called automatically when the app goes to the background.
stop()Stops recording and detaches the app-state and navigation listeners.
getSessionId()The current session id, or null before init has finished or while waiting for consent.

Components

ExportDescription
<AnyReplay>Wrap your app in it. It lets the recorder find React's committed tree and observe touches, and renders a View with flex: 1 that declines every gesture.
touchProps()The props <AnyReplay> spreads onto its view, for apps that need to attach touch observation to their own root view instead.

Status values

The handle returned by init has status() with the same values as the browser SDK: idle, awaiting-consent, recording, sampled-out and stopped.

Delivery

  • The same endpoint, payload format, rate limits and refusal codes as the web recorder — see ingest responses.
  • Failed chunks are kept and retried, up to maxBufferedEvents. Chunks are cut to about 256 KB as well as 200 events, so a backlog after an outage goes out as several requests. Being offline, a timeout, 429 or 5xx never stops recording — it waits 2 s doubling to a minute, with jitter, and at least what Retry-After asks (at most ten minutes). A 413 sends the events again in smaller chunks. A 402 stops recording and no new session starts for two minutes, across launches. Other 4xx answers stop recording for this launch. (0.1.4 stopped after five failed deliveries in a row.)
  • A tap is recorded once, when the finger lifts, and only if it moved less than 10 points from where it went down — a scroll or a swipe is not a tap. (0.1.4 recorded a touch when it started and again as it moved.)
  • The agent string says iPad on an iPad and Tablet on an Android tablet, so tablets are filed as tablets; and an app that comes back after 30 minutes or more in the background starts a new session.
  • Bundled images are uploaded once per project, by SHA-256 hash, after the recorder asks ingest which it already has.

Source: react-native/src.