@bro-sdk/react-native
v0.1.2
Published
React Native SDK for Bro analytics & push notifications platform
Readme
@bro-sdk/react-native
React Native SDK for Bro — analytics & push notifications platform.
Install
npm install @bro-sdk/react-nativePeer dependencies:
npm install @react-native-async-storage/async-storageQuick Start
import { createBro } from "@bro-sdk/react-native";
// createBro is async (loads persisted IDs from AsyncStorage)
const bro = await createBro({
apiKey: "bro_pk_xxxxxxxxxxxx",
});
// Track screen views
bro.screen("Home");
// Track events
bro.track("add_to_cart", { productId: "abc-123", price: 29.90 });
// Identify users
bro.identify("user-123", { name: "Augusto" });Features
- Screen tracking — dedicated
screen()method for navigation - Event batching — queues events and sends in batches (20 events or every 5s)
- Session tracking — automatic 30-minute session windows
- AsyncStorage persistence — anonymous/user IDs survive app restarts
- Memory fallback — works even if AsyncStorage isn't available
- Push token registration — register FCM/APNS tokens with one call
- Singleton pattern —
createBro()once,getBro()anywhere
Configuration
const bro = await createBro({
apiKey: "bro_pk_xxxxxxxxxxxx", // Required
appVersion: "1.0.0", // Sent with events
debug: false, // Log events to console
flushInterval: 5000, // ms between flushes
flushSize: 20, // Events per batch
});API
bro.track(name, properties?) // Track custom event
bro.identify(userId, traits?) // Identify user
bro.screen(name, properties?) // Track screen view
bro.reset() // Clear identity (logout)
bro.flush() // Force-send queued events
bro.shutdown() // Stop the SDK
// Push
bro.registerPushToken(token, "fcm" | "apns")
bro.unregisterPushToken(token)Singleton Access
import { createBro, getBro } from "@bro-sdk/react-native";
// Initialize once (e.g., in App.tsx)
await createBro({ apiKey: "bro_pk_xxx" });
// Access anywhere
import { getBro } from "@bro-sdk/react-native";
const bro = getBro();
bro.track("event_name");Push Notifications
Register FCM or APNS tokens after obtaining them from your push library:
import messaging from "@react-native-firebase/messaging";
const token = await messaging().getToken();
await bro.registerPushToken(token, "fcm");License
MIT
