# Handling Multiple Push Providers

 There's a new version available!

These pages cover version 5 of our SDK, but a newer version is available. In general, we suggest that you update to the latest version to take advantage of new features and fixes.

*   Are you new to our SDKs? [Check out the latest docs.](/integrations/sdk/react-native/getting-started)
*   Otherwise, [learn about updating to the latest version](/integrations/sdk/react-native/whats-new/)

## How to handle multiple push providers[](#how-to-handle-multiple-push-providers)

If Customer.io is the only SDK that you use in your app to display push notifications, then you don’t need to do anything special to display push notifications.

But, if you use another module in your app that can display push notifications like `expo-notifications`, `react-native-push-notification`, or `rnfirebase`, these modules can take over push handling by default and prevent your app from receiving push notifications from Customer.io.

You can solve this problem using one (and **only one**) of the methods below, but we typically recommend [the first option](#cio-process-notification-payloads), because it doesn’t require you to write native code! Please note that the following methods will always return `true` for iOS.

## Option 1 (Recommended): Set Customer.io SDK to handle push clicks[](#cio-process-notification-payloads)

You can pass the payloads of other message services to Customer.io whenever a device receives a notification, and our SDK can process it for you. The SDK exposes the `onMessageReceived` method for this that takes two arguments:

*   a `message.data` object containing the incoming notification payload
*   a `handleNotificationTrigger` boolean indicating whether or not to trigger a notification.
    *   `true` (default) means that the Customer.io SDK will generate the notification and track associated metrics.
    *   `false` means that the SDK will process the notification to track metrics but *will not* generate a notification on the device.

You’ll use the `onMessageReceived` like this:

```javascript
CustomerIO.pushMessaging.onMessageReceived(message).then(handled => {
  // If true, the push was a Customer.io notification and handled by our SDK 
  // Otherwise, `handled` is false
});
```

You can pass values in `onMessageReceived` by listening to notification events exposed by other SDKs. Make sure that you add listeners in the right places to process notifications that your app receives when it’s in the foreground and add background listeners that might be required by other SDK to process notifications that your app receives when it’s in background/killed state.

If you *always* send rich push messages (with `image` and/or `link`), adding event listeners is enough. But if you send custom push payloads using the `notification` object or send simple push messages (with just a `body` and `title`), you may get duplicate notifications when your app is backgrounded because Firebase itself displays notifications sent using the `notification` object.

To avoid this, You can pass `false` in `handleNotificationTrigger` to track metrics for simple and custom payload push notifications. To simplify this behavior, the SDK also exposes an `onBackgroundMessageReceived` method that automatically suppresses pushes with the notification object when your app is in background.

If you use `rnfirebase`, you can setup listeners like this:

 Foreground Listener

#### Foreground Listener[](#Foreground Listener)

To listen to messages in the foreground, set `onMessage` listener where appropriate:

```javascript
useEffect(() => {
  const unsubscribe = messaging().onMessage(async remoteMessage => {
    CustomerIO.pushMessaging.onMessageReceived(remoteMessage).then(handled => {
        // If true, the push was a Customer.io notification and handled by our SDK 
        // Otherwise, `handled` is false
    });
  });

  return unsubscribe;
}, []);
```

 Background Listener

#### Background Listener[](#Background Listener)

To listen to messages when app is in background/killed state, set `setBackgroundMessageHandler` in your `index.js` file

```javascript
messaging().setBackgroundMessageHandler(async remoteMessage => {
  CustomerIO.pushMessaging.onBackgroundMessageReceived(remoteMessage).then(handled => {
    // If true, the push was a Customer.io notification and handled by our SDK 
    // Otherwise, `handled` is false
  });
});
```

## Option 2: Register Customer.io Messaging Service[](#register-messaging-service)

You can register Customer.io’s messaging service in your `Manifest` file so that we handle all notifications for your app. You can do this by adding the following code under the `<application>` tag in the `AndroidManifest.xml` file in your app’s `android` folder.

```xml
<service
    android:name="io.customer.messagingpush.CustomerIOFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
```

 The Customer.io SDK will handle all your push notifications

The code above hands all push notifications responsibility to our SDK, meaning:

*   Your app will receive all simple and rich push notifications from Customer.io.
*   When your app is in the background, it can receive push notifications with a `notification` payload from other services.
*   Your app **cannot receive** `data`\-only push notifications from another service.

## Manually track push metrics[](#manual-push-metrics)

If you need to manually track push metrics when you use multiple push providers (like when you display notifications yourself or use another library), you can parse a push notification payload and send `opened` or `delivered` events to the SDK in relevant callbacks:

```javascript
CustomerIO.trackMetric({
  deliveryID: deliveryID,
  deviceToken: deviceToken,
  event: MetricEvent.Opened,
});
```

The `trackMetric` method requires the following parameters:

*   `deliveryID`: The delivery ID extracted from the push notification payload
*   `deviceToken`: The device token extracted from the push notification payload
*   `event`: The metric event type, either `MetricEvent.Opened` or `MetricEvent.Delivered`