Note: To enable this feature, speak to your Customer Success Manager.
Push notifications enable you to communicate with your mobile app users, even if they are not currently using your app. It can be an automated one-to-one message (such as cart abandonment reminders), or a “blast” push (let all of your users know about a special sale).
Note: This article is about triggering push notifications with Experience APIs. If you use the Dynamic Yield mobile SDK, learn how to create push notifications with our mobile SDK.
How it works
In the Dynamic Yield console, define the trigger (for example, cart abandonment or price drop) and create the variations (the content of the notifications) in a JSON format.
As a developer:
- Use Experience API to serve the right variation to your users. You are in charge of delivering and rendering the notification.
- Use the events endpoint to let Dynamic Yield know which users are opted in and out of push notifications.
- Use the events endpoint to track opens and clicks on the variations.
Note that the following events are mandatory:
- Opt-in/Opt-out events
- Omni-channel events (such as Login, Newsletter Subscription, or Signup)
The pushID value is generated by Firebase/Apple Console after the user consents to receive push notifications from the app.
Limitations
- Variables with user or product data are currently not supported.
- Preview for the campaign is not available.
- No out-of-the-box testing. To test the campaign, create a test audience. For example, based on an event.
- Push notifications can only be sent to users who provided active consent for cookies and who opted in for messages.
If active cookie consent is not implemented, the campaign works for all users. - Push notifications can be sent only to identified users.
Prerequisites
- For Firebase, provide the Firebase Server Key.
- For Apple Console, provide:
- P12 file (including its password)
- Environment (development/production)
- Topic (also called BundleID)
Provide this information to your technical account manager.
Step 1: Let Dynamic Yield know which users can receive push notifications
Use the events endpoint to send Dynamic Yield information about which users are opted in and out.
DYID, DYID_server, and session dy are mandatory. If the _dyid cookie exists, pass its value here. Otherwise, in case both this parameter and dyid_server are not passed, a new user ID will be created by Dynamic Yield and returned in the response.
{
"user": {
"dyid": "-4350463893986789401",
"dyid_server": "-4350463893986789401"
},
"session": {
"dy": "ohyr6v42l9zd4bpinnvp7urjjx9lrssw"
},
"events": [
{
"name": "Push Opt-In",
"properties": {
"dyType": "message-optin-v1",
"pushID": "100"
}
}
]
}
DYID, DYID_server, and session dy are mandatory. If the _dyid cookie exists, pass its value here. Otherwise, in case both this parameter and dyid_server are not passed, a new user ID will be created by Dynamic Yield and returned in the response.
{
"user": {
"dyid": "-4350463893986789401",
"dyid_server": "-4350463893986789401"
},
"session": {
"dy": "ohyr6v42l9zd4bpinnvp7urjjx9lrssw"
},
"events": [
{
"name": "Push Opt-Out",
"properties": {
"dyType": "message-optout-v1",
"pushID": "100"
}
}
]
}
https://dy-api.com/v2/collect/user/event (US data center)
https://dy-api.eu/v2/collect/user/event (EU data center)
{
"user": {
"id": ""john_123"
},
"sessionId": "iquahngaishe2koh",
"events": [
{
"name": "Push Opt-Out",
"properties": {
"dyType": "message-optout-v1",
"pushID": "100"
}
}
]
}
https://dy-api.com/v2/collect/user/event (US data center)
https://dy-api.eu/v2/collect/user/event (EU data center)
{
"user": {
"id": "john_123"
},
"sessionId": "iquahngaishe2koh",
"events": [
{
"name": "Push Opt-In",
"properties": {
"dyType": "message-optin-v1",
"pushID": "100"
}
}
]
}
Step 2: Create a push notification campaign
Create the trigger and the variation in the Dynamic Yield console:
- Go to Push Notifications › Add New.
- Choose the trigger type:
- Abandoned Cart View: A user added an item to the shopping cart without completing a purchase.
- Abandoned Product View: A user who viewed a product without completing a purchase.
- Abandoned category view: A user who viewed a category page without completing a purchase.
- Custom: Trigger by any event (user logged in, rated a product).
- Schedule: push notification at a specific time to all users or users who belong to a chosen audience. To enable this trigger, contact your Customer Success Manager.
- Each trigger has the relevant settings for that trigger:
- Delay Send: The time it takes from the moment the user triggers the campaign until we send.
- Cancel Send: An action that needs to happen to not send the push notification, even though the user has triggered the campaign.
- Frequency Capping: A limit for the number of notifications (of this trigger) that can be sent to a user in a given timeframe.
- Click Next to define the targeting settings as you would for any Experience.
- Create variations. This is the content of your message, in a JSON format. Meaning, it is not the design, but the information that is needed, to design it on our app code later.
Sample template JSON code for iOS
{ "aps": { "alert": { "title": "Title example", "subtitle": "Subtitle example", "body": "Body example" } }, "data": { "tracking": "${dyTracking}" } }
Sample template JSON code for Android
{ "message": { "notification": { "title": "Title Example", "body": "Body Example" } }
"data": { "tracking": "${dyTracking}" }
} -
The attributes aps → body (iOS) / message → body (Android) and data → tracking (both iOS and Android) are mandatory. The attributes title and subtitle are optional.
- You can add more variations and test different messages, or add more experiences to target different audiences with different messages.
- Save and publish your campaign.
Step 3: Locally save data from the triggered notifications payload
Whenever an opted-in user triggers a push notification campaign, you will get its payload. Save trackingData locally, as you will need to populate it into the engagement data API calls.
"engagements": [
{
"type": "PN_CLICK",
"trackingData": {
"rri": "987001424",
"sectionID": "9878785",
"reqTs": "1652622484055",
"userID": "4656722918296846673",
"version": "2",
"events": [
{
"ver": "101482916",
"expVisitId": "4032971100745578591",
"smech": "",
"vars": [101098971],
"exp": "1296028",
"mech": "1"
}
]
}
}
]
Note that PN_CLICK refers to the type of engagement you are reporting on and might differ depending on the type of campaign. Also, the values of the trackingData attributes are dynamic and unique in every push notification.
Step 4: Implement events to track delivery and clicks
Notify Dynamic Yield about the delivery of push notifications for reporting and testing purposes using this endpoint:
Note: You must add the DYTrackingData you received from Dynamic Yield. You get the tracking data as a part of the push notification and should save it locally on the device to track clicks.
https://dy-api.com/v2/collect/user/engagement
{
"user": {
"dyid": "-4350463893986789401",
"dyid_server": "-4350463893986789401"
},
"session": {
"dy": "ohyr6v42l9zd4bpinnvp7urjjx9lrssw"
},
"engagements" [
{
"type": "PN_IMP",
"trackingData": { "rri": "987001424", "sectionID": "9878785", "reqTs":
"1652622484055", "userID": "4656722918296846673", "version": "2", "events":
[ { "ver": "101482916", "expVisitId": "4032971100745578591", "smech": "",
"vars": [101098971], "exp": "1296028", "mech": "1" } ] }
}
]
}
https://dy-api.com/v2/collect/user/engagement
{
"user": {
"dyid": "-4350463893986789401",
"dyid_server": "-4350463893986789401"
},
"session": {
"dy": "ohyr6v42l9zd4bpinnvp7urjjx9lrssw"
},
"engagements": [
{
"type": "PN_CLICK",
"trackingData": { "rri": "987001424", "sectionID": "9878785", "reqTs":
"1652622484055", "userID": "4656722918296846673", "version": "2", "events":
[ { "ver": "101482916", "expVisitId": "4032971100745578591", "smech": "",
"vars": [101098971], "exp": "1296028", "mech": "1" } ] }
}
]
}
https://dy-api.com/v2/collect/user/engagement
{
"user": {
"id": "john_123"
},
"session": {
"custom": "asdrtewqaa"
},
"engagements": [
{
"type": "PN_IMP",
"trackingData": { "rri": "987001424", "sectionID": "9878785", "reqTs":
"1652622484055", "userID": "4656722918296846673", "version": "2", "events":
[ { "ver": "101482916", "expVisitId": "4032971100745578591", "smech": "",
"vars": [101098971], "exp": "1296028", "mech": "1" } ] }
}
]
}
https://dy-api.com/v2/collect/user/engagement
{
"user": {
"id": "john_123"
},
"session": {
"custom": "asdrtewqaa"
},
"engagements": [
{
"type": "PN_CLICK",
"trackingData": { "rri": "987001424", "sectionID": "9878785", "reqTs":
"1652622484055", "userID": "4656722918296846673", "version": "2", "events":
[ { "ver": "101482916", "expVisitId": "4032971100745578591", "smech": "",
"vars": [101098971], "exp": "1296028", "mech": "1" } ] }
}
]
}