📄️ Introduction
This document describes how to integrate the B2Metric React Native SDK into a mobile application. The SDK lets your app capture product analytics events, manage sessions automatically, and report push notification activity, all with a single JavaScript / TypeScript API that works identically on iOS and Android.
📄️ Installation
The SDK is published to the public npm registry under the scope @b2metric/react-native-sdk.
📄️ Initialization
The SDK must be initialized once, as early as possible in your app's lifecycle, before any other SDK method is called. The recommended location is your root component's mount effect, so initialization runs before the first screen renders.
📄️ Event Tracking
Event tracking is the primary purpose of the SDK. Once init has resolved, you can call logEvent anywhere in your app to record a user action. Calls are synchronous and very cheap — the actual network delivery happens later, in the background, in batches.
📄️ Push Notifications
The SDK does not handle push notification delivery or display — that remains the responsibility of your existing notification stack (typically Firebase Messaging for FCM/HMS and APNS via React Native's own push APIs for iOS). What the SDK provides is the link between a device's push token and B2Metric, so that B2Metric campaigns can target the device, and a method to report when a notification leads to an app open.
📄️ Manual Flush
Events are delivered automatically in the background — either when the batch size is reached, or when the flush interval expires, whichever happens first. In most situations this is exactly what you want: it minimises battery and network usage by amortising the cost of a network round trip across many events.
📄️ Shutdown
In long-running React Native apps you usually never need to shut the SDK down — it can simply keep running for the lifetime of the process. However, in a few specific situations a clean shutdown is useful:
📄️ Automatic Behavior
Beyond the events you explicitly log, the SDK handles a number of standard analytics concerns on its own. Understanding what is automatic is important: it tells you what you do not need to build yourself, and what data will appear in the B2Metric project without any additional code.
📄️ Troubleshooting
If something is not behaving as expected, the first step is almost always to enable debug logging and look at the console output. The SDK is intentionally verbose at logLevel: 'debug' — every state transition, every batch attempt, and every validation decision is logged.