Skip to main content

React Native SDK

A lightweight React Native SDK for iOS and Android.

Requirements

  • React Native 0.71+
  • Expo SDK 49+ (if using Expo)

Installation

npm install @mostly-good-metrics/react-native

That's it! Expo includes AsyncStorage by default.

Bare React Native

npm install @mostly-good-metrics/react-native @react-native-async-storage/async-storage
cd ios && pod install

Quick Start

Initialize

import MostlyGoodMetrics from '@mostly-good-metrics/react-native';

MostlyGoodMetrics.configure('mgm_proj_your_api_key');

Track Events

// Simple event
MostlyGoodMetrics.track('button_clicked');

// Event with properties
MostlyGoodMetrics.track('purchase_completed', {
product_id: 'SKU123',
price: 29.99,
currency: 'USD',
});

Identify Users

// Set user identity
MostlyGoodMetrics.identify('user_123');

// Reset identity (e.g., on logout)
MostlyGoodMetrics.resetIdentity();

Configuration Options

import { version } from './package.json';

MostlyGoodMetrics.configure('mgm_proj_your_api_key', {
baseURL: 'https://mostlygoodmetrics.com',
environment: 'production',
appVersion: version,
maxBatchSize: 100,
flushInterval: 30,
maxStoredEvents: 10000,
enableDebugLogging: __DEV__,
trackAppLifecycleEvents: true,
});
OptionDefaultDescription
baseURLhttps://mostlygoodmetrics.comAPI endpoint
environment"production"Environment name
appVersion-App version (required for install/update tracking)
maxBatchSize100Events per batch
flushInterval30Auto-flush interval in seconds
maxStoredEvents10000Max cached events
enableDebugLoggingfalseEnable console output
trackAppLifecycleEventstrueAuto-track lifecycle events

Automatic Events

EventWhenProperties
$app_installedFirst launch after install$version
$app_updatedFirst launch after version change$version, $previous_version
$app_openedApp became active (foreground)-
$app_backgroundedApp resigned active (background)-

Manual Flush

MostlyGoodMetrics.flush();

// Check pending events
const count = await MostlyGoodMetrics.getPendingEventCount();
console.log(`${count} events pending`);