AdvaitaADVAITA DOCS
GitHubGet started
Mobile SDKv1.0.0MIT License

React Native SDK

@acai/react-native-sdk is backed by native iOS and Android modules via the React Native bridge. It supports session tracking, COPPA controls, and a middleware pipeline.

Installation

Shell
npm install @acai/react-native-sdk
# iOS — install native pods
cd ios && pod install

Initialise

JavaScript
import { Acai } from '@acai/react-native-sdk'
// Call once at app root, useEffect is ideal
useEffect(() => {
async function setup() {
const acai = Acai.getInstance()
await acai.init('YOUR_API_KEY')
await acai.setServerUrl('https://events.yourdomain.com/2/httpapi')
}
setup()
}, [])

Track events

JavaScript
const acai = Acai.getInstance()
await acai.logEvent('Button Clicked')
await acai.logEvent('Purchase Completed', {
product_id: 'prod_123',
price: 49.99,
currency: 'USD',
})
// Flush the queue
await acai.uploadEvents()

Identify users

JavaScript
import { Identify } from '@acai/react-native-sdk'
await acai.setUserId('user_abc123')
await acai.setUserProperties({ plan: 'pro', company: 'Acme Corp' })
const identify = new Identify()
identify.set('plan', 'pro')
identify.setOnce('signup_date', '2024-01-15')
identify.add('session_count', 1)
identify.unset('trial_active')
await acai.identify(identify)
await acai.setGroup('company', 'Acme Corp')
// Log out
await acai.setUserId(null)
await acai.regenerateDeviceId()

Config reference

The React Native SDK uses method-based configuration (no config object at init):

MethodDescription
setServerUrl(url)Override the collector endpoint.
setOptOut(bool)Disable all event tracking.
setEventUploadThreshold(n)Events before automatic flush.
setEventUploadPeriodMillis(ms)Time-based flush interval.
setEventUploadMaxBatchSize(n)Max events per request.
trackingSessionEvents(bool)Auto-track session start/end events.
setMinTimeBetweenSessionsMillis(ms)Session gap threshold in ms.
enableCoppaControl()Enable COPPA mode (disables IDFA collection).
disableCoppaControl()Disable COPPA mode.
enableLogging(bool)Toggle verbose SDK logging.
addEventMiddleware(fn)Add an event enrichment middleware function.