@codematic/opencdp-react-native
v2.0.2
Published
Codematic OpenCDP React Native SDK — native wrapper over Android/iOS OpenCDP SDKs
Readme
OpenCDP React Native SDK
Mobile client SDK for OpenCDP on React Native. v2.0 wraps the native Android and iOS OpenCDP SDKs for full capability parity with Flutter.
Documentation
Published guides on docs.opencdp.io:
- Mobile E2E integration guide
- Identity and devices
- Rich push images
- React Native SDK docs
- Example app guide
Requirements
- React Native >= 0.72 (or Expo SDK 50+ with development build — Expo Go is not supported)
- iOS 13+ / Android API 24+
Install
npm install @codematic/opencdp-react-native
# Optional: only needed if you use CDPClient in Node smoke tests
npm install @react-native-async-storage/async-storageExpo
Add the config plugin to app.json:
{
"expo": {
"plugins": ["@codematic/opencdp-react-native/app.plugin.js"]
}
}Then create a dev build:
npx expo prebuild
npx expo run:ios # or run:androidBare React Native
cd ios && pod install && cd ..Autolinking picks up android/ and ios/ from this package.
Native dependencies:
- Android:
io.opencdp:opencdp-android:1.0.0-alpha02 - iOS:
OpenCDPpod ~> 0.1.1
Quick start
import { OpenCDPSDK } from '@codematic/opencdp-react-native';
await OpenCDPSDK.initialize({
config: {
cdpApiKey: 'apikey_...',
debug: true,
autoTrackDeviceAttributes: true,
enableInAppMessages: true,
},
});
await OpenCDPSDK.instance.identify({
identifier: 'user_123',
properties: { plan: 'pro' },
});
await OpenCDPSDK.instance.track({
eventName: 'purchase',
properties: { amount: 99.9 },
});
await OpenCDPSDK.instance.trackScreenView({
title: 'Home',
});
await OpenCDPSDK.instance.registerDeviceToken({ fcmToken: '...' });
OpenCDPSDK.instance.addInAppListener((message) => {
console.log('In-app message', message.deliveryId);
});
await OpenCDPSDK.setupPushNotifications();
await OpenCDPSDK.handleForegroundPushDelivery({ delivery_message_id: '...' });API surface
| Capability | React Native |
|------------|--------------|
| Initialize | OpenCDPSDK.initialize({ config }) |
| Identify / track / clear | OpenCDPSDK.instance.* |
| Screen / lifecycle | trackScreenView, trackLifecycleEvent |
| Device token | registerDeviceToken({ fcmToken?, apnToken? }) |
| Push metrics | OpenCDPSDK.handleForegroundPushDelivery, handleBackgroundPushDelivery, handlePushNotificationOpen, handlePushActionClick |
| Android notification UI | OpenCDPSDK.showActionableNotification(data) |
| Pending launch (Android) | OpenCDPSDK.handlePendingNotificationLaunch() |
| In-app | syncInAppMessages, addInAppListener, trackInAppImpression/Click/Dismiss |
| Debug (native) | debugTestHostFailover, debugTestQueueRetry, debugDrainQueue |
See SDK_CONTRACT.md for cross-SDK mapping.
Node / test console
CDPClient remains a pure HTTP client for the opencdp-test-console smoke runner in Node. On device, always use OpenCDPSDK (native-backed).
Example app
cd example
npm install
npx expo prebuild
npx expo run:iosPush setup
- Android: Wire FCM in your
FirebaseMessagingServiceusing helpers from nativeOpenCDPPushSetup(see Android SDK README). - iOS: Call
OpenCDPSDK.setupPushNotifications()after init; forward APNs token viaregisterDeviceToken({ apnToken }). Add Notification Service Extension for big-picture push (see iOS SDK README).
Configuration
| Option | Default | Description |
|--------|---------|-------------|
| cdpApiKey | required | OpenCDP API key |
| cdpEndpoint | production gateway | Primary gateway URL |
| cdpFallbackEndpoints | .com, .xyz | Fallback hosts |
| throwErrorsBack | false | Throw on validation/network errors |
| autoTrackScreens | false | Auto-track navigation (native) |
| trackApplicationLifecycleEvents | true | App lifecycle events |
| autoTrackDeviceAttributes | true | Register device on init when token stored |
| sendToCustomerIo | false | Dual-write to Customer.io (requires CIO SDK linked in native) |
| enableInAppMessages | false | Enable in-app sync / listeners |
| iOSAppGroup | — | App group for NSE / background push |
