@newly/sdk-react-native
v0.1.0
Published
Newly analytics SDK for React Native / Expo apps
Readme
@newly/sdk-react-native
Newly analytics for Expo / React Native apps.
Install
npm install @newly/sdk-react-nativePeers (all optional, all shipped by the Newly expo-template):
expo-secure-store (identity), @react-native-async-storage/async-storage
(offline queue), expo-crypto (uuids), react-native (AppState lifecycle).
A missing peer never crashes the app — the SDK degrades to in-memory adapters
and says so through onError.
Initialize (once, in the root _layout.tsx)
import Constants from 'expo-constants';
import { Newly } from '@newly/sdk-react-native';
Newly.init({
ingestKey: Constants.expoConfig?.extra?.newlyIngestKey,
apiUrl: Constants.expoConfig?.extra?.newlyApiUrl,
});Track
Newly.analytics.track('item_purchased', { item_id: 'x', amount_cents: 999 });
Newly.analytics.identify('user_123', { plan: 'pro' });
Newly.analytics.screen('Cart');
Newly.analytics.flush(); // usually unnecessary — batching flushes on size/time/backgroundPlatform notes
- No gzip in v1 — Hermes lacks
CompressionStream; the ingest endpoint accepts identity-encoded JSON. - Offline events queue in AsyncStorage (10k cap, restart-safe) and retry with jittered exponential backoff.
- The SDK never throws into the host app; failures surface only through the
optional
onErrorhook. - Sampling (
sampling: 0..1) drops events client-side with one persisted per-install coin flip — consistent per user, not per event. - Android install referrer: pass
getInstallReferrerinNewly.initif the host app integrates a referrer module; parsed intofirst_touch_*.
