Integrate Bro into your app.
SDKs for Web and React Native. Analytics, user identification, and push notifications — all in one platform.
Getting Started
Install the SDK for your platform:
# Web (React, Next.js, Vite, etc.)
npm install @bro-sdk/web
# React Native
npm install @bro-sdk/react-nativeYou will need two values from the Bro dashboard:
Settings → App → API Key
bro_pk_xxxxxxxxxxxx
Settings → App → VAPID Public Key
Required for web push only
Web SDK
Initialize
Call createBro() once at app startup. It returns a singleton — use getBro() to access it from anywhere.
import { createBro } from '@bro-sdk/web'
const bro = createBro({
apiKey: 'bro_pk_xxxxxxxxxxxx',
autoPageView: true, // automatic page views
trackClicks: true, // automatic click tracking
})Track Events
bro.track('purchase', {
amount: 99.90,
currency: 'BRL'
})Identify Users
bro.identify('user-123', {
name: 'Augusto',
plan: 'pro'
})Use Anywhere
Access the same instance from any file with getBro():
import { getBro } from '@bro-sdk/web'
const bro = getBro()React Native SDK
Initialize
The React Native SDK uses an async initializer. Call it once at app startup (e.g. in App.tsx).
import { createBro } from '@bro-sdk/react-native'
await createBro({
apiKey: 'bro_pk_xxxxxxxxxxxx',
appVersion: '1.0.0'
})Screen Tracking
import { getBro } from '@bro-sdk/react-native'
const bro = getBro()
bro.screen('ProductScreen')track() and identify() work the same as the Web SDK.
Web Push
Web push requires three steps. All three are required — skipping any one will result in push not working.
webPush: true but forgetting to call subscribeToPush(). The init only registers the service worker — you must explicitly call subscribeToPush() to prompt the user and register the token.1Copy the service worker
Copy bro-sw.js from the SDK package to your project's public/ folder. This file must be served at the root of your domain (e.g. https://yoursite.com/bro-sw.js).
cp node_modules/@bro-sdk/web/bro-sw.js public/bro-sw.jsThe service worker handles receiving and displaying push notifications in the background. Without it, the browser can't show notifications.
2Initialize with push enabled
Pass webPush: true and your VAPID public key to createBro().
import { createBro } from '@bro-sdk/web'
const bro = createBro({
apiKey: 'bro_pk_xxxxxxxxxxxx',
webPush: true,
vapidPublicKey: 'your-vapid-public-key'
})3Subscribe to push
Call subscribeToPush() to actually register the browser. This is what prompts the user for permission, creates the push subscription, and registers the token with the Bro backend.
const subscription = await bro.subscribeToPush()
if (subscription) {
// Push enabled — token registered with Bro
} else {
// User denied or browser doesn't support push
}Common patterns
Subscribe on page load:
const bro = createBro({
apiKey: 'bro_pk_xxxxxxxxxxxx',
webPush: true,
vapidPublicKey: 'your-vapid-public-key'
})
bro.subscribeToPush()Subscribe on button click:
async function enableNotifications() {
const bro = getBro()
const sub = await bro.subscribeToPush()
if (sub) showToast('Notifications enabled!')
}Other push methods
// Check permission status
const permission = await bro.getPushPermission()
// 'granted' | 'denied' | 'default'
// Unsubscribe
await bro.unsubscribeFromPush()Mobile Push (React Native)
For React Native, use Firebase Cloud Messaging (FCM) tokens. FCM tokens work for both Android and iOS.
import messaging from '@react-native-firebase/messaging'
import { getBro } from '@bro-sdk/react-native'
// Get FCM token
const token = await messaging().getToken()
// Register with Bro
const bro = getBro()
await bro.registerPushToken(token)
// Unregister on logout
await bro.unregisterPushToken(token)API Reference
@bro-sdk/web
| Method | Description |
|---|---|
| createBro(config) | Initialize SDK (singleton) |
| getBro() | Get existing instance |
| track(event, props?) | Track custom event |
| identify(userId, traits?) | Identify user |
| subscribeToPush() | Subscribe to web push |
| unsubscribeFromPush() | Unsubscribe from web push |
| getPushPermission() | Get notification permission status |
| flush() | Flush event queue immediately |
@bro-sdk/react-native
| Method | Description |
|---|---|
| createBro(config) | Initialize SDK (async, singleton) |
| getBro() | Get existing instance |
| track(event, props?) | Track custom event |
| screen(name, props?) | Track screen view |
| identify(userId, traits?) | Identify user |
| registerPushToken(token) | Register FCM/APNS token |
| unregisterPushToken(token) | Unregister push token |
| flush() | Flush event queue immediately |