React Native SDK

@userflux/react-native

UserFlux's React Native SDK - send your mobile app analytics data to the UserFlux platform.

Getting Started

1. Install the package

npm install @userflux/react-native

or with Yarn:

yarn add @userflux/react-native

2. Install peer dependencies

The SDK requires these peer dependencies:

npm install @react-native-async-storage/async-storage @react-native-community/netinfo react-native-device-info

3. Platform-specific setup

iOS

cd ios && pod install

Android

No additional setup required for Android.

4. Initialize the SDK

Configuration Options

The initialize method accepts the following options:

Option
Type
Default
Description

autoCapture

Array<string>

[]

Events to automatically capture: 'screen_views', 'app_opens', 'all'

autoEnrich

boolean

true

Automatically enrich events with device and location data

defaultTrackingProperties

object

{}

Properties to include with every event

trackSession

boolean

true

Track sessions with unique identifiers

disableUserIdStorage

boolean

false

Don't persist user ID in AsyncStorage

blockCommonBots

boolean

true

Block tracking from emulators/simulators

debugMode

boolean

false

Enable debug logging

Core Methods

Tracking Events

Identifying Users

Screen Tracking

React Navigation Integration

For automatic screen tracking with React Navigation:

Batch Tracking

Session Management

Sessions are automatically managed with a 5-minute timeout. When the app goes to background and returns after 5 minutes, a new session is created.

User Management

Default Properties

Update default properties that are sent with every event:

Offline Support

Events are automatically queued when the device is offline and sent when connectivity is restored:

App Lifecycle Events

Track app lifecycle events:

Device Information

The SDK automatically collects device information when autoEnrich is enabled:

  • Platform (iOS/Android)

  • Device model and brand

  • OS version

  • App version and build number

  • Screen dimensions

  • Timezone and locale

  • Network carrier

  • Memory and storage info

Deep Linking

Track app opens from deep links:

TypeScript Support

The SDK includes TypeScript definitions:

Best Practices

  1. Initialize Early: Call UserFlux.initialize() as early as possible in your app lifecycle

  2. User Identification: Call identify() as soon as you have user information

  3. Screen Tracking: Integrate with your navigation solution for automatic screen tracking

  4. Batch Events: Use trackBatch() when tracking multiple related events

  5. Cleanup: Call UserFlux.cleanup() when your app unmounts (if needed)

Troubleshooting

Events not being sent

  1. Check that you've initialized the SDK with a valid API key

  2. Verify network connectivity

  3. Enable debug mode to see logs: { debugMode: true }

  4. Check that events are not being blocked by emulator detection

Storage issues

  • The SDK uses AsyncStorage for persistence

  • Ensure AsyncStorage is properly installed and linked

  • Storage is automatically cleared on reset()

Session management

  • Sessions timeout after 5 minutes of inactivity

  • New sessions are created when the app returns from background after timeout

  • Session IDs are not persisted between app launches

Last updated