SDK — React Native
NPM install and API for @layers/react-native. Alpha — subject to change.
Status: alpha. @layers/react-native is published to npm (current
version at the time of writing: 2.2.0). The API is still evolving and
is pre-1.0 stable.
Install
npm i @layers/react-native
cd ios && pod installPeer dependencies (declared by the package):
react >= 18react-native >= 0.70@react-native-async-storage/async-storage >= 1.21@react-native-community/netinfo >= 11
Autolinking handles the native binding for iOS (CocoaPods) and Android
(Gradle). For Expo managed projects, install @layers/expo instead.
Initialize
// App.tsx
import { useEffect } from 'react';
import Layers from '@layers/react-native';
export default function App() {
useEffect(() => {
Layers.init({
apiKey: 'unused-but-required-by-type',
appId: 'app_xxx',
environment: __DEV__ ? 'development' : 'production',
enableDebug: __DEV__,
});
}, []);
return <RootNavigator />;
}Notes:
- The call is
Layers.init(...), notLayers.configure(...). apiKeyis required by the TypeScript type but the server currently only validatesappId(theX-Api-Keyheader is accepted and ignored). Pass any non-empty string.- The ingest endpoint is always
https://in.layers.comby default; override withbaseUrlif you're on a custom domain.
Track events
await Layers.track('purchase_success', {
revenue: 9.99,
currency: 'USD',
product_id: 'premium_yearly',
store: 'app_store',
});Use canonical event names from Standard events
where possible — names outside that set are stored in sdk_events but
dropped at the CAPI relay.
Screen tracking
await Layers.screen('Checkout', { cart_size: 3 });For Expo Router apps, the package ships a helper:
import { useLayersExpoRouterTracking, LayersExpoRouter } from '@layers/react-native';
import { usePathname, useGlobalSearchParams } from 'expo-router';
// In _layout.tsx
<LayersExpoRouter usePathname={usePathname} useGlobalSearchParams={useGlobalSearchParams} />Identify
Layers.setAppUserId('user_42');
await Layers.setUserProperties({ plan: 'premium' });
// On logout
Layers.clearAppUserId();Note: setAppUserId is synchronous. There is no Layers.identify(id, traits) / Layers.reset() — use setAppUserId + setUserProperties
and clearAppUserId instead.
Consent
await Layers.setConsent({ advertising: true, analytics: true });setConsent takes a { advertising?, analytics? } object, not a
boolean. The remote-config endpoint can also gate advertising / analytics
globally via killswitches.
ATT (iOS)
await Layers.requestTracking(); // shows the system promptInfo.plist entry is still required:
<key>NSUserTrackingUsageDescription</key>
<string>We use this to personalize your experience.</string>Connector & debug surface
The SDK exposes several advanced surfaces that are not guaranteed stable in the current alpha:
Layers.connectors.*— per-network connector config/metrics (meta,tiktok,snap,google). Native pixel SDKs are NOT bundled; the server-side CAPI relay is what actually forwards events.Layers.skan.*— SKAdNetwork preset + rule management.Layers.deepLinks.*— deep-link configuration + listeners.Layers.att.*— ATT-specific helpers.Layers.debug.*— overlay, metric dumps. Use during development only.
Treat these as experimental — signatures may change before 1.0.
Expo
For Expo managed projects, use @layers/expo (which wraps this package
with a config plugin). See the Expo guide.