Push notifications
UpdatedThere's a new version available!
These pages cover version 2 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.
- Otherwise, learn about updating to the latest version
Get started setting up push notifications for Android. Our Android SDK supports push notifications over FCM.
This page is part of a setup flow for the SDK. Before you continue, make sure you've implemented previous features—i.e. you can't receive push notifications before you identify people!
Before you begin
This page explains how to receive push notifications using our SDK. However, before you can send push notifications to your audience, you need to enable Customer.io to send push notifications through Firebase Cloud Messaging (FCM).
This process lets you receive basic push notifications in your app—a title and a message body. To send a notification with an image, link, etc, complete the process on this page, and then see our rich push documentation.
Check out our sample apps!
How it works
Before a device can receive a push notification, you must:
- Set up FCM.
- Set up push.
- Identify a person. When someone starts the app, they automatically generate a device token. Identifying the person associates the device token with the person in Customer.io, so that they can receive push notifications.
- Set up a campaign to send a push notification through the Customer.io composer.
Set up push
You must implement the Push Messaging SDK to use push notification features.
implementation 'io.customer.android:messaging-push-fcm:<version-here>'
Initialize the push module.
CustomerIO.Builder( siteId = "siteId", apiKey = "apiKey", appContext = application, ).apply { addCustomerIOModule(ModuleMessagingPushFCM()) autoTrackScreenViews(true) setRequestTimeout(8000L) setRegion(Region.US) build() }
The SDK adds a FirebaseMessagingService
to the app manifest automatically, so you don’t have to perform additional setup to handle incoming push messages.
If your application implements its own FirebaseMessagingService
, make sure that when you call onMessageReceived
and onNewToken
methods, you also call CustomerIOFirebaseMessagingService.onMessageReceived
and CustomerIOFirebaseMessagingService.onNewToken
respectively.
class FirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
val handled = CustomerIOFirebaseMessagingService.onMessageReceived(message)
if (handled) {
logger.breadcrumb(this, "Push notification has been handled", null)
}
}
override fun onNewToken(token: String) {
CustomerIOFirebaseMessagingService.onNewToken(token)
}
Push notifications launched from the SDK are currently posted to our default channel—[your app name] Channel
. In the future, we plan to let you customize channels/categories so that users can subscribe and unsubscribe to content categories as necessary.
Capture push metrics
Customer.io supports device-side metrics that help you determine the efficacy of your push notifications: delivered
when a push notification is received by the app and opened
when a push notification is clicked.
By default, the messaging-push-fcm
SDK automatically tracks opened
and delivered
for push notifications originating from Customer.io. Otherwise, you can track push metrics with the trackMetric
method.
CustomerIO.instance().trackMetric(
deliveryID = deliveryId,
deviceToken = deliveryToken,
event = MetricEvent.delivered
)