Quick Start Guide
UpdatedSetup process overview
React Native lets you build native mobile apps with JavaScript. Our React Native SDK helps you integrate Customer.io to identify
people, track
their activity, and send both push notifications and in-app messages.
- Add a React Native integration to Customer.io get your API keys.
- Install the SDK.
- Initialize the SDK.
- Identify and Track
- Push Notifications
- In-App
1. Add a React Native connection to your Customer.io workspace
You need to add a new React Native connectionRepresents an integration between Customer.io and another service or app under Data & Integrations > Integrations. A connection in Customer.io provides you with API keys and settings for your integration. in Customer.io to get your CDP API key. See Get your CDP API key for details.
2. Install the SDK
Make sure you set up your React Native environment first. You must use React Native 0.76.9 or later.
Open your terminal and go to your project folder.
Install the
customerio-reactnative
package using NPM or Yarn:npm install customerio-reactnative # or yarn add customerio-reactnative
Set up your project to support iOS and/or Android deployments:
iOS
For iOS, install CocoaPods dependencies:
pod install --repo-update --project-directory=ios
Make sure your minimum iOS deployment target is set to
13.0
in both yourPodfile
and Xcode project settings.Android
For Android, include the Google Services plugin by adding the following to your project-level
android/build.gradle
file:buildscript { repositories { google() // Google's Maven repository } dependencies { classpath 'com.google.gms:google-services:<version-here>' // Google Services plugin } } allprojects { repositories { google() // Google's Maven repository } }
Add the plugin to your app-level
android/app/build.gradle
:apply plugin: 'com.google.gms.google-services' // Google Services plugin
Download
google-services.json
from your Firebase project and place it inandroid/app/google-services.json
.
3. Initialize the SDK
Add your CDP API key and site ID to your configuration.
- CDP API Key: You’ll find this key in your React Native connection.
- Site ID: You’ll find this value in your workspace under > Workspace Settings > API and webhook credentials.
Initialize the SDK in your app. Add the following code to your main component or App.js file:
import React, { useEffect } from 'react'; import { CioConfig, CioRegion, CioLogLevel, CustomerIO, PushClickBehaviorAndroid } from 'customerio-reactnative'; useEffect(() => { const initializeCustomerIO = async () => { const config: CioConfig = { cdpApiKey: 'YOUR_CDP_API_KEY', // Required region: CioRegion.US, logLevel: CioLogLevel.Debug, trackApplicationLifecycleEvents: true, inApp: { siteId: 'YOUR_SITE_ID', // Required for in-app messaging } }; await CustomerIO.initialize(config); }; initializeCustomerIO(); }, []);
Run your application to ensure everything is set up correctly:
- iOS:
npx react-native run-ios
- Android:
npx react-native run-android
- iOS:
4. Identify and Track
Identify a user in your app using the
CustomerIO.identify
method. You must identify a user before you can send push notifications and personalized in-app messages.import { CustomerIO } from "customerio-reactnative"; const identifyUserExample = async () => { await CustomerIO.identify({ userId: 'react-native-test-user@example.com', traits: { firstName: 'John', lastName: 'Doe', email: 'react-native-test-user@example.com', subscriptionStatus: 'active', }, }); console.log('User identified successfully'); };
Track a custom event using the
CustomerIO.track
method. Events help you trigger personalized campaigns and track user activity.import { CustomerIO } from "customerio-reactnative"; const trackCustomEventExample = async () => { await CustomerIO.track('purchased_item', { product: 'Premium Subscription', price: 99.99, currency: 'USD' }); console.log('Custom event tracked successfully'); };
Track screen views to trigger in-app messages associated with specific screens.
import { CustomerIO } from "customerio-reactnative"; const trackScreenViewExample = async () => { await CustomerIO.screen('ProductDetails'); console.log('Screen view tracked successfully'); };
5. Push Notifications
Set up your push notification credentials in Customer.io:
- iOS: Upload your Apple Push Notification certificate (.p8 file).
- Android: Upload your Firebase Cloud Messaging server key (.json format).
Request push notification permissions from the user:
import { CustomerIO, CioPushPermissionStatus } from "customerio-reactnative"; const requestPushPermissions = async () => { const permissionStatus = await CustomerIO.pushMessaging.showPromptForPushNotifications({ ios: { sound: true, badge: true } }); switch (permissionStatus) { case CioPushPermissionStatus.Granted: console.log('Push notifications enabled'); break; case CioPushPermissionStatus.Denied: case CioPushPermissionStatus.NotDetermined: console.log('Push notifications denied'); break; } };
For iOS: to ensure that metrics are tracked, configure Background Modes. In Xcode, enable “Remote notifications” under Capabilities > Background Modes.
For Android: add notification icon resources:
- Place a notification icon file named
ic_notification.png
in your drawable folders. - Make sure your app’s
AndroidManifest.xml
has the proper FCM permissions.
- Place a notification icon file named
6. In-App
To enable in-app messaging, all you need to do is add the site ID. Remember, you’ll find your site ID under Data & Integrations > Integrations > Customer.io API: Track in the Connections tab.
Ensure that the SDK is initialized with the site ID in your app. You can call the
initialize
method from your components or services:
import { CioConfig, CustomerIO } from "customerio-reactnative";
import { useEffect } from "react";
useEffect(() => {
const initializeCustomerIO = async () => {
const config: CioConfig = {
cdpApiKey: 'YOUR_CDP_API_KEY',
inApp: {
siteId: 'YOUR_SITE_ID',
}
};
await CustomerIO.initialize(config);
};
initializeCustomerIO();
}, []);
Check out our code samples!
You’ll find a complete, working sample app in our React Native SDK’s example directory. If you get stuck, you can refer to the sample app to see how everything fits together.