Firebase Cloud Messaging (FCM)
Create a Firebase project here to get started.
Setup
- Go to the FCM Provider Configuration
- Go to your Firebase Project
- Go to Project Settings
- Click "Service Accounts"
- Click "Generate new private key"
- Copy the private key JSON
- Paste the private key JSON into the FCM Provider Configuration
- Click "Install Provider" or "Save"
iOS Support
- Add Firebase to your iOS project
- In your Firebase Project Settings
- Click "Cloud Messaging"
- Under Apple app configuration, select your iOS project
- Go to your Apple Developer Account
- Click "Certificates"
- Click "Keys"
- Click the "+" button
- Name the Key
- Click "Enable" on "Apple Push Notifications Service (APNs)"
- Click "Continue"
- Click "Register"
- Click "Download"
- Go back to your Firebase Project > Apple apps > Your app > APNs Authentication Key > Click "Upload"
- Enter the required information
- Click "Upload"
Getting FCM Tokens
With a Courier Mobile SDK
Using a Courier Mobile SDK is the best way to set this up. All Courier Mobile SDKs sync FCM tokens to Courier and will be automatically managed. This allows you to send pushes directly to a user_id
rather than FCM tokens.
Mobile SDK | FCM Token Management | Tracking Analytics |
---|---|---|
Android | Automatic | Automatic |
iOS | Setup | Automatic |
React Native | Setup | Automatic |
Flutter | Setup | Automatic |
Without a Courier Mobile SDK
Follow the Firebase Cloud Messaging Setup for the platform you would like to use.
What FCM tokens look like:
dYeufxa20kwFnykCny-gIN:APA91bEJxheJmH_zDvoHfPsCDZstJcuYfWuQrhztywoejlAK5HmDBEYNm7R8fNzk3bjQ3lPmkVi8uaoIX94SMV4ZXRPxG_IhfT_OkfmVHCAN6GtdAvELOXSjp6z1UHVVmMnAFTOa7YxW
You will need to sync, store, and manage your user's FCM tokens. This likely will require you to create entries in your database, deploy separate endpoints, and add extra development time that can be avoided with a Courier Mobile SDK.
If you'd like Courier delivery and click tracking, you will also need to manually make a request to the trackingUrl
.
Sending Messages
This is a common example request you can make to the send
api that shows:
providers.firebase-fcm.override.body.data.YOUR_CUSTOM_KEY
for adding custom data to your payload. This is usually used for opening a specific screen in your app when the user takes action on a push notification. Firebase requires thedata
key to be flat. More details about FCM custom data here.providers.firebase-fcm.override.body.apns
for applying iOS specific values. You can learn more about these here.
Sending to a user_id
(Recommended)
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
{
"message": {
"to": {
"user_id": "YOUR_USER_ID"
},
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"firebase-fcm"
]
},
"providers": {
"firebase-fcm": {
"override": {
"body": {
"data": {
"YOUR_CUSTOM_KEY": "YOUR_CUSTOM_VALUE"
},
"apns": {
"payload": {
"aps": {
"sound": "ping.aiff",
"badge": 99
}
}
}
}
}
}
}
}
}
}'
Sending to a firebaseToken
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
{
"message": {
"to": {
"firebaseToken": "YOUR_FCM_TOKEN"
},
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"firebase-fcm"
]
},
"providers": {
"firebase-fcm": {
"override": {
"body": {
"data": {
"YOUR_CUSTOM_KEY": "YOUR_CUSTOM_VALUE"
},
"apns": {
"payload": {
"aps": {
"sound": "ping.aiff",
"badge": 99
}
}
}
}
}
}
}
}
}
}'
Sending to multiple firebaseTokens
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
{
"message": {
"to": [
{ "firebaseToken": "FCM_TOKEN_ONE" },
{ "firebaseToken": "FCM_TOKEN_TWO" }
],
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"firebase-fcm"
]
},
"providers": {
"firebase-fcm": {
"override": {
"body": {
"data": {
"YOUR_CUSTOM_KEY": "YOUR_CUSTOM_VALUE"
},
"apns": {
"payload": {
"aps": {
"sound": "ping.aiff",
"badge": 99
}
}
}
}
}
}
}
}
}
}'
Automatic Courier Mobile SDK Formatting
By default, Courier automatically formats the FCM payload to make a better developer experience for you if you are working with a Courier Mobile SDK. Here you can manage the automatic FCM settings.
What this setting does:
- Automatically delivers Android push notifications in the background. This allows you to get more accurate push notification delivery tracking and to use your own custom Android notification style all the time.
- Supports Courier's iOS Notification Service Extension for better push notification delivery tracking.
Here is an example of what the formatted send
request looks like if enabled:
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
"message": {
"to": {
"user_id": "YOUR_USER_ID"
},
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"firebase-fcm"
]
},
"firebase-fcm": {
"override": {
"notification": null, // Prevents Android system tray from taking over notification presentation
"data": { // Used by Courier Android SDK to present your customized notification and track notification delivery in all Android states
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"apns": {
"payload": {
"aps": {
"mutable-content": 1, // Used by the Courier iOS SDK Notification Service Extension
"sound": "ping.aiff", // Provides a default sound or vibration if iOS device ringer is off
"alert": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
}
}
}
}
}
}
}
}'