Handle Custom Keys Sent with Message Payload

Send additional data with your push notifications using custom keys. Custom keys let you pass information beyond the standard notification title, body, and badge. Additional information can include product IDs, user preferences, tracking parameters, or any data your app needs. When a user taps a notification, your app can extract these custom values from the notification’s userInfo dictionary and use them to navigate to specific content, update the UI, trigger analytics events, or perform other custom logic.

For example, an e-commerce app can include a product ID in a custom key to open the product detail page directly. A news app can pass an article ID to display the full story. Or you can include tracking parameters that third-party analytics tools use to measure campaign effectiveness.

Enable custom keys on the Administration page in Marketing Cloud Engagement Setup before sending notifications with custom data.

The MobilePush Administration page in Marketing Cloud Engagement, showing the Custom Keys option enabled.

Next, implement custom key support in your app by extending your push notification handler to extract the push’s userInfo dictionary and the values it contains.

This code example shows how to handle custom keys using version 10 or later of the SDK.

For version 9 of the SDK, use this code.

For version 8.1 of the SDK, use this code.

For version 8.0 of the SDK, use this code.

For version 7 of the SDK, use this code.