React Native SDK
Track events on iOS and Android with the FlashAnalytics React Native SDK.
The React Native SDK adds lifecycle capture, deep links, navigation tracking, JavaScript error capture, native crash reporting, experiment assignment, and push lifecycle helpers to iOS and Android apps.
Install
npm install @flash-analytics/react-native@2.1.9 react-native-device-infocd ios && pod installreact-native-device-info is a peer dependency.
Initialize
import { FlashAnalytics } from '@flash-analytics/react-native';
const analytics = new FlashAnalytics({
appId: 'YOUR_APP_ID',
endpoint: 'https://api.flashanalytics.app',
captureAppLifecycle: true,
captureScreenViews: true,
captureDeepLinks: true,
captureErrors: true,
captureNativeCrashes: true,
captureVariants: true,
capturePushLifecycle: true,
pushTracking: {
android: {
defaultChannelId: 'flash-default',
defaultNotificationTtlMs: 5 * 60 * 1000,
},
},
});Auto capture
- App lifecycle via
captureAppLifecycle - Deep links via
captureDeepLinks - JavaScript errors via
captureErrors - Native crashes via
captureNativeCrashes - Experiment auto-assignment via
captureVariants - Push lifecycle helpers via
capturePushLifecycle
Navigation tracking
analytics.setNavigationRef(navigationRef);
// or manually
analytics.trackScreenChange('Checkout');Error tracking
try {
await riskyOperation();
} catch (error) {
analytics.trackError(error, 'network_failure');
}enableErrorTracking still exists for older setups, but new apps should use captureErrors.
Experiments and remote config
const assignments = await analytics.autoAssignExperiments();
const variant = await analytics.assignExperiment('checkout-cta');
const config = await analytics.fetchRemoteConfig();Push lifecycle
notification_deliverednotification_openednotification_dismissednotification_action_clickednotification_expired
React Native JavaScript alone cannot observe every OS callback. iOS delivery and expiry require a UNNotificationServiceExtension. iOS open, dismiss, and action events require UNUserNotificationCenterDelegate. Android dismiss and action events require native BroadcastReceiver and PendingIntent wiring.
Session access
const session = analytics.getSession();
console.log(session?.id);
console.log(session?.estimatedExpiresAt);
console.log(session?.estimatedTtlMs);