Custom push payloads

You can send highly customized push notifications using a Custom Payload. If you’ve integrated with our SDK, custom payloads let you send images and link customers to pages in your app when they tap your message.

Getting started with custom payloads

Creating a custom payload for your push notification grants access to a greater range of push features, like images and deep links—provide that your app is set up to support those features.

To enter a custom payload, click Custom Payload when composing your push notification.

image.png
image.png

You can then write or paste your custom code into the editor. There are different tabs for Android and iOS so that you can send custom code for each platform separately but, if you are using Firebase Cloud Messaging, you can just use the Android tab to send custom code that will be used for both Android and iOS.

Before you begin

Figure out what you want your message to do: do you want to send people to a deep link in your app or show them an image? Before you compose your message, make sure that your app supports that functionality. You may have to develop your app to handle some custom payload features.

If your payload includes links (like the link key, supported by our SDKs), you may need to know the format of deep links—links to pages within your app. Talk to your development team if you need help understanding the link scheme within your app.

You should also understand which push provider(s) you use. If you use Firebase Cloud Messaging, you may be able to construct a single payload supporting both Android and iOS devices. If you use Apple’s Push Notification service (APNs), you’ll need to enter different payloads for both iOS and Android devices.

When you have your payload, you’ll need to ensure that:

  1. Your JSON code is valid.
  2. The code you use follows the guidelines for the specific provider:

Here’s the most basic example of a custom payload for sending to Android and iOS devices via Firebase Cloud Messaging:

{
  "message": {
      "notification": {
        "body": "YOUR MESSAGE BODY HERE",
        "title": "YOUR MESSAGE TITLE HERE"
      }
  }
}

Here’s the most basic example of a custom payload for sending to iOS devices via Apple Push Notification Service:

{
  "aps": {
    "alert": {
      "body": "YOUR MESSAGE BODY HERE",
      "title": "YOUR MESSAGE TITLE HERE"
    }
  }
}

Personalize push notifications

You can use liquidA syntax that supports variables, letting you personalize messages for your audience. For example, if you want to reference a person’s first name, you might use the variable {{customer.first_name}}. in your custom payload. While you can technically use liquid in any string field, you probably want to limit yourself to the body, title, and subtitle (on iOS) fields.

Here’s a basic Android (and iOS via FCM) example using customer and event data:

{
  "message": {
      "notification": {
         "body": "Hi {{customer.first_name}}, your {{event.event_title}} has been booked!",
         "title": "All set!"
      }
  }
}

This results in a push notification that looks like this on iOS:

Custom push payload reference

While you can send push notifications to both iOS and Android devices using FCM, if you want to provide a custom payload, you must provide separate payloads for your iOS and Android audiences.

If your custom payload does not match the shape below, or you provide an incorrect data type for a key, your notification may fail.

 Check your iOS notification setup

your iOS push payload changes based on whether you send notifications through Google’s Firebase cloud messaging platform (FCM) or the Apple Push Notification service (APNs). Make sure you reference the correct reference for your push provider.

FCM custom push payload

Your custom payload’s shape and keys depend on whether you use Customer.io’s SDKs or developed your own custom integration with our API. If you send a message with our SDKs, you’ll place the entire message within the message.data object. This works for both Android and iOS platforms.

The message.data object can also contain custom data that your app to interpret. Custom data isn’t supported natively; it takes additional development. Talk to your app’s developer(s) to understand the custom data that you can pass to your app.

If you developed a custom integration, you can set a global notification—for both Android and iOS—in the message.notification object. You can pass additional options for the android push in the meassage.android.notification object.

You’ll find example payloads below depending on whether you’ve integrated with our SDK or wrote your own custom integration.

Our SDK natively supports the keys below. However, if you’ve extended the SDK or done additional app development, your payload may contain other fields.

{
  "message": {
    "data": {
      "title": "string", //(optional) The title of the notification.
      "body": "string", //The message you want to send.
      "link": "string", //Deep link in the format remote-habits://deep?message=hello&message2=world
      "image": "string" //https URL to an image you want to include in the notification
    }
  }
}
KeyTypeDescription
message.data object contains keys interpreted by the Android and iOS SDKs (when sending over FCM)
title Optional, string

The notification's title.

body Optional, string

The notification's body text.

link

Optional, string

A deep link (to a page in your app), or a link to a web page. For more information about deep links, see our rich push documentation

image

Optional, string

The URL of an HTTPS image that you want to use for your message.

{
    "message": {
        "notification": {
            "title": "string", //(optional) The title of the notification.
            "body": "string" //(optional) The message you want to send.
        },
        "data": {
            //Use if you've integrated with our SDK.
            //Optional key-value pairs that your app interprets.
            //We don't validate the keys or values you provide.
        },
        "android": {
            "notification": {
                //(Optional) Contains options specific to an android notification. 
                "icon": "string", 
                "sound": "string",
                "tag": "string",
                "color": "#rrggbb",
                "click_action": "string",
                "body_loc_key": "string",
                "body_loc_args": "stringified,array",
                "title_loc_key": "string",
                "title_loc_args": "stringified,array"
            }
        }
    }
}
KeyTypeDescription
message.notification object
title Optional, string

The notification's title.

body Optional, string

The notification's body text.

message.data object
Custom keysOptional, any typeCustom key-value pairs that your app will interpret. We don't validate the keys or data you provide. Customer.io and FCM assume that your app understands how to interpret this data.
message.android.notification object —Android notification options
icon Optional, string

Sets the notification icon to myicon for drawable resource myicon. If you don't send this key, FCM displays the launcher icon from your app manifest.

sound Optional, string

The sound that plays when the device receives the notification. Supports "default" or the filename of a sound resource bundled in your app. Sound files must reside in /res/raw/.

tag Optional, string

Identifier to replace existing notifications in the notification drawer. If empty, each request creates a new notification.

If you specify a tag, and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.

color Optional, string

The notification's icon color, in #rrggbb format.

click_action Optional, string

The action that occurs when user taps on the notification. Launches an activity with a matching intent filter when a person taps the notification.

body_loc_key Optional, string

The key to the body string in the app's string resources that you want to use to localize the body text to the user's current localization. See String Resources for more information.

body_loc_args Optional, JSON array as string

Variable string values used in place of the format specifiers in body_loc_key to localize the body text to the user's current localization. See Formatting and Styling for more information.

title_loc_key Optional, string

The key to the title string in the app's string resources that you want to use to localize the title text to the user's current localization. See String Resources for more information.

title_loc_args Optional, JSON array as string

Variable string values used in place of the format specifiers in title_loc_key to localize the title text to the user's current localization.

See Formatting and Styling for more information.

iOS custom push payload (FCM)

 This section is for iOS over Firebase only!

If you send push notifications to iOS using the Apple Push Notification service (APNs), you should see our APNs payload reference instead.

Before you send a push notification, make sure you understand how you’re integrated with Customer.io.

{
  "message": {
    "apns": {
      "payload": {
        "CIO": {
          "push": {
            "link": "string", //Deep link in the format remote-habits://deep?message=hello&message2=world
            "image": "string" //https URL to an image you want to include in the notification
          }
        },
        "aps": {
          "mutable-content": 1,
          "alert": {
            "title": "string", //(optional) The title of the notification.
            "body": "string" //(optional) The message you want to send.
          }
        }
      }
    }
  }
}

When you send a custom notification, you can set a default message.notification with a body. The iOS custom payload portions of your notification appear in the apns object.

The following shows the basic shape of an iOS custom push payload for FCM. You’ll find a deeper explanation of the iOS payload options that FCM supports in Google’s documentation.

{
  "message": {
    "notification": {
      // default notification
      "title": "string",
      "body": "string"
    },
    "apns": {
      "headers": {
        // headers defined in Apple Push Notification Service.
        "apns-priority": 10
      },
      "payload": {
        "aps": {
          // iOS message options go here
          "mutable_content": true      
        }
      },
      "fcm_options": {

      }
    } 
  }
}

iOS custom push payload (APNs)

 This section is only for apps that use Apple’s Push Notification service (APNs)!

You can also send push notifications to iOS devices using Google’s Firebase Cloud Messaging (FCM) service. Make sure you use the correct payload for the messaging provider you set up in your Workspace Settings.

Whether you use our SDK or developed your own integration, your push notification will normally include a aps.alert object with a body, reflecting the message you want to send. You can pass additional options for the push in the aps object (outside of the alert). Where the alert represents the message, these settings tell the device how to handle the message—whether to play a sound or add the message to a thread of notifications, etc.

If you use our SDK, you’ll include additional options—like deep links or images—in the CIO.push object. Otherwise, you can pass additional, custom data outside the aps object. This custom data is something you’ve extended our SDK, or done your own development, to support. Talk to your app’s developer(s) to understand the custom data that you can pass to your app. You can omit the alert and send a silent push, with just custom data (setting "content-available": 1), though it’s not the most common use case.

{
  "aps": {
    "alert": { 
    //can be string or object
    //alert object keys
      "body": "string",
      "title": "string",
      "subtitle": "string",
      "launch-image": "string",
    // localization arguments
      "title-loc-key": "string",
      "title-loc-args": ["array", "of", "strings"],
      "subtitle-loc-key": "string",
      "subtitle-loc-args": ["array", "of", "strings"],
      "loc-key": "string",
      "loc-args": ["array", "of", "strings"]
    },
    // message options
    "badge": number,
    "sound": "string or dictionary",
    "thread-id": "string",
    "category": "string",
    "content-available": number, 0 (default) or 1,
    "mutable-content": number, 0 (default) or 1,
    "target-content-id": string,
  },
  // options supported by Customer.io's SDK
  "CIO": {
    "push": {
        "link": "string", // deep links in the format remote-habits://deep?message=hello&message2=world
        "image": "string" // https URL to an image, including the file extension
    }
  },
  // additional custom data
  "custom-keys": "Optional, any type"
}
KeyTypeDescription
aps.alert can be a string (simple message) or object (recommended). Below are the keys supported by the aps.alert object.
title Optional, string

The title of the notification. Apple Watch displays this string in the short look notification interface.

subtitle

Optional, string

Additional information about the purpose of the notification.

body Optional, string

The notification's body text. While this is "optional" in the sense that you can send an empty notification to perform a background update, you should consider this key required otherwise.

launch-image

String

The name of the launch image file. If a person launches your app, the this is the image or storyboard that appears, instead of your app's normal launch image.

title-loc-key

String

The value in your strings file representing a localized title string. Use this key instead of the title to retrieve the title from your app’s Localizable.strings files.

title-loc-args

Array of strings

An array of replacement string values for variables in your title string. Each %@ character in the title-loc-key string is replaced by a value from this array. The first item in the array replaces the first instance of the %@ character in the string, the second item replaces the second instance, and so on.

subtitle-loc-key

String

The value in your strings file representing a localized subtitle string. Use this key, instead of the subtitle key, to retrieve the subtitle from your app's Localizable..strings file.

subtitle-loc-args

Array of strings

An array of replacement string values for variables in your title string. Each %@ character in the string specified by subtitle-loc-key is replaced by a value from this array. The first item in the array replaces the first instance of the %@ character in the string, the second item replaces the second instance, and so on.

loc-key

String

The value in your strings file representing a localized message string. Use this key, instead of the body key, to retrieve the message text from your app's Localizable..strings file.

loc-args

Array of strings

An array of strings containing replacement values for variables in your message text. Each %@ character in the string specified by loc-key is replaced by a value from this array. The first item in the array replaces the first instance of the %@ character in the string, the second item replaces the second instance, and so on.

aps options—these are keys determining how the device handles the `alert`.

badge

Optional, number

The number to display in a badge on your app’s icon. Use 0 to remove the current badge

sound Optional, string

The name of a sound file in your app’s main bundle or in the Library/Sounds folder of your app’s container directory. Use "default" to play the system sound.

thread-id

Optional, string

An identifier to group related notifications. This value corresponds to the thread.Identifier property in the UNNotification.Content object.

category

Optional, string

The notification’s type. This string must correspond to the identifier of one of the UNNotification.Category objects you register at launch time. See Declaring Your Actionable Notification Types.

content-available

Optional, number (0 or 1)

The background notification flag. Enter 1 to perform a background update and don't include the alert, badge, or sound keys in your payload. See Pushing Background Updates to Your App.

mutable-content

Optional, number (0 or 1)

The notification service app extension flag. Set to 1 to pass the notification to your notification service app extension before delivery. Use your extension to modify the notification’s content. See Modifying Content in Newly Delivered Notifications.

target-content-id

Optional, string

The identifier of the window brought forward. The value of this key is populated on the UNNotification.Content object created from the push payload. Access this value using the UNNotification.Content object's target.Content.Identifier property.

CIO.push keys handled by our iOS SDK

link

Optional, string

A deep link (to a page in your app), or a link to a web page. For more information about deep links, see our rich push documentation

image

Optional, string

The URL of an HTTPS image that you want to use for your message.

Custom keys — optional, any type. Custom keys and values that your app is set up to interpret—image handling, etc. We don't validate the keys or data you provide. Customer.io and APNs assume that your app understands how to interpret this data.

Got feedback?

We’re hoping to get your feedback on how you’re using custom payloads, if there’s anything you’re struggling with, or if there’s anything you’re really enjoying about it and want to make sure we keep.

Let us know!

Copied to clipboard!