@userboost/react-native
v1.1.10
Published
UserBoost React Native SDK for mobile analytics
Maintainers
Readme
@userboost/react-native
UserBoost React Native SDK for mobile analytics and user tracking.
Installation
npm install @userboost/react-nativeRequired Peer Dependencies
npm install @react-native-async-storage/async-storageOptional Dependencies (for enhanced device context)
npm install react-native-device-infoUsage
Basic Setup
import UserBoost from '@userboost/react-native';
// Initialize in your App.js or index.js
UserBoost.init({
apiKey: 'ub_your_api_key_here',
debug: __DEV__ // Enable debug logging in development
});Track Events
UserBoost.event('button_clicked', {
user: { id: 'user123' },
properties: {
button_name: 'signup',
screen: 'home'
}
});Identify Users
UserBoost.identify({
id: 'user123',
email: '[email protected]',
traits: {
name: 'John Doe',
plan: 'premium'
}
});Features
Automatic Device Context
The SDK automatically collects:
- Device model and brand
- OS version (iOS/Android)
- App version and build number
- Screen resolution
- Device locale and timezone
- RTL layout detection
Persistent User Data
User data is automatically persisted to AsyncStorage and restored on app restart.
App Lifecycle Handling
Events are automatically flushed when the app goes to background.
Network Resilience
- Automatic retry with exponential backoff
- Offline queue management
- Smart error handling
API Reference
Core Methods
init(config)- Initialize the SDKevent(name, data)- Track an eventidentify(userData)- Identify a userflush()- Manually flush queued eventsreset()- Reset user data and queuedebug(enabled)- Enable/disable debug logging
React Native Specific
getDeviceContext()- Get current device contextcheckStorageAvailability()- Check if AsyncStorage is working
Configuration Options
interface UserBoostConfig {
apiKey: string; // Required: Your UserBoost API key
endpoint?: string; // Optional: Custom API endpoint
debug?: boolean; // Optional: Enable debug logging
user?: UserData; // Optional: Initial user data
batchSize?: number; // Optional: Events per batch (default: 10)
flushInterval?: number; // Optional: Auto-flush interval (default: 2000ms)
maxRetries?: number; // Optional: Max retry attempts (default: 3)
}Troubleshooting
AsyncStorage Issues
If you see storage warnings, ensure AsyncStorage is properly installed:
npx react-native unlink @react-native-async-storage/async-storage
npx react-native link @react-native-async-storage/async-storageFor React Native 0.60+, use autolinking:
cd ios && pod installDeviceInfo Issues
DeviceInfo is optional. If you don't need enhanced device context, you can skip this dependency.
TypeScript Support
Full TypeScript support is included. All types are re-exported from @userboost/core.
Platform Support
- React Native 0.60+
- iOS 9.0+
- Android API level 16+
