Send Data to App via Push Notification

Overview

When sending push notifications, you can optionally include additional data in the notification payload. This data can be used to customize the app experience, such as pre-populating search filters or determining which pages to open based on app conditions. To include additional data, simply add fields under the Additional Data section when composing a push notification in the OneSignal portal or via the REST API.

🚧

targetUrl

As per our documentation Open URL in App , if an Additional Data field targetUrl is provided, this URL will be launched in the app when the notification is opened. If you prefer to open a URL conditionally in JavaScript use a different field, such as openUrl, to avoid the automatic page launch.

Once the notification is opened, a JavaScript function on your page, median_onesignal_push_opened(), will be triggered with the data passed as an argument.

Add Additional Data to send to your app

Add Additional Data to send to your app

Implementation Guide

Here’s an example of how to define the median_onesignal_push_opened() function on your page to process the received data:

↔️Median JavaScript Bridge

// Define this function on your page; it will be called automatically by the app when opened
function median_onesignal_push_opened(data) {
    console.log(JSON.stringify(data));
}
// Expected output
{
  'airport': 'sfo',
  'direction': 'outbound',
  'dateRange': 'week'
}