Skip to main content

Firebase Cloud Messaging (FCM)


Firebase Project Required

Create a Firebase project here to get started.

Setup

Setup Video

  1. Go to the FCM Provider Configuration
  2. Go to your Firebase Project
  3. Go to Project Settings
  4. Click "Service Accounts"
  5. Click "Generate new private key"
  6. Copy the private key JSON
  7. Paste the private key JSON into the FCM Provider Configuration
  8. Click "Install Provider" or "Save"

iOS Support

Setup Video

  1. Add Firebase to your iOS project
  2. In your Firebase Project Settings
  3. Click "Cloud Messaging"
  4. Under Apple app configuration, select your iOS project
  5. Go to your Apple Developer Account
  6. Click "Certificates"
  7. Click "Keys"
  8. Click the "+" button
  9. Name the Key
  10. Click "Enable" on "Apple Push Notifications Service (APNs)"
  11. Click "Continue"
  12. Click "Register"
  13. Click "Download"
  14. Go back to your Firebase Project > Apple apps > Your app > APNs Authentication Key > Click "Upload"
  15. Enter the required information
  16. 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 SDKFCM Token ManagementTracking Analytics
AndroidAutomaticAutomatic
iOSSetupAutomatic
React NativeSetupAutomatic
FlutterSetupAutomatic

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
Manual Implementation Requirements

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:

  1. 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 the data key to be flat. More details about FCM custom data here.
  2. providers.firebase-fcm.override.body.apns for applying iOS specific values. You can learn more about these here.
cURL
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
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
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:

  1. 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.
  2. 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
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 😁"
}
}
}
}
}
}
}
}'
Was this helpful?