Skip to main content

Quick Start — React Native SDK

Prerequisites​

Step 1 — Initialize​

import { OpenCDPSDK } from '@codematic/opencdp-react-native';

await OpenCDPSDK.initialize({
config: {
cdpApiKey: 'YOUR_CDP_API_KEY',
cdpEndpoint: 'YOUR_DATA_GATEWAY_URL',
debug: true,
autoTrackDeviceAttributes: true,
enableInAppMessages: true,
},
});

Step 2 — Identify a user​

await OpenCDPSDK.instance.identify({
identifier: 'user_123',
properties: {
plan: 'pro',
email: '[email protected]',
},
});
warning

identifier must not be an email address.

Step 3 — Track an event​

await OpenCDPSDK.instance.track({
eventName: 'app_opened',
properties: { source: 'quick_start' },
});

Step 4 — Track a screen view​

await OpenCDPSDK.instance.trackScreenView({
title: 'Home',
properties: { tab: 'main' },
});

Step 5 — Register device token (push)​

await OpenCDPSDK.instance.registerDeviceToken({
fcmToken: 'YOUR_FCM_TOKEN', // Android
// apnToken: 'YOUR_APNs_TOKEN', // iOS
});

Step 6 — Set up push handlers​

await OpenCDPSDK.setupPushNotifications();

See Push notifications for FCM/APNs wiring and rich images.

Verify it worked​

With debug: true, confirm identify and track POSTs succeed in Metro / native logs.

Next steps​