- Print
Coupon click events
- Print
This guide provides instructions on how to integrate the coupon popup provided by Shoplive with your coupon system.
LINK / LINK (New window)
How to integrate a coupon when the coupon click event is set to Link or Link (New window).
messageCallback
The messageCallback
is called when a coupon is clicked. This allows you to define custom actions for each event.
Action | Payload | Description |
---|---|---|
LINK | json object | The |
LINK_NEW_WINDOW | json object | The messageCallback function is called when the coupon click event is set to Link(New window). If you do not override it, the URL will be displayed in a new window in the web and the SDK will enter PIP mode and call NAVIGATION. |
Payload object
Property name | Type | Example | Description |
---|---|---|---|
campaignKey | string | “asdf1234” | Unique key of campaign |
popupResourceId | string | “1234” | Unique key of popup |
type | string | “COUPON” | ”BANNER” | ”NOTICE” | Type of popup |
url | string | “https://shoplive.cloud” | Link URL |
Sample code
If you want to navigate to a page after adding parameters to the link URL when you click a coupon in the player, you can define LINK
or LINK_NEW_WINDOW
as shown below.
To open a page in the current window, use location.href
.
To open a page in a new window, use window.open
.
Download coupon
How to integrate a coupon when the coupon click event is set to Download coupon.
messageCallback
The messageCallback
is called when a coupon is clicked. This allows you to define custom actions for each event.
Action | Payload | Description |
---|---|---|
DOWNLOAD_COUPON | json object | When you click a coupon, the coupon code value and the popup type are passed.
|
Payload object
Property name | Type | Example | Description |
---|---|---|---|
campaignKey | string | “asdf1234” | Unique key of campaign |
coupon | string | “12341234” | Coupon code |
popupResourceId | string | “1234” | Unique key of popup |
type | string | “COUPON” | ”BANNER” | ”NOTICE” | Type of popup |
Sample code
To process coupon download by calling the customer server API when a coupon is clicked in the player, you can define DOWNLOAD_COUPON
as follows.
You can process coupon download by calling the customer server API with fetch
, and manipulate the coupon UI (hide/show/blur) depending on the processing result.
User define
How to integrate a coupon when the coupon click event is set to User define.
You can define the information in JSON format and add it to the payload object.
messageCallback
The messageCallback
is called when a coupon is clicked. This allows you to define custom actions for each event.
Action | Payload | Description |
---|---|---|
CUSTOM_ACTION | json object | When a coupon is clicked, it passes information about the popup along with the payload object that the user defines. |
Payload Object
The payload object of the CUSTOM_ACTION
event includes the payload object that the user defines in the coupon edit window.
Property name | Type | Example | Description |
---|---|---|---|
campaignKey | string | “asdf1234” | Unique key of campaign |
id | string | “1234” | Unique key of popup |
payload | object | { “coupon”: “12341234”, “url”: “https://shoplive.cloud”, … } | Custom payload object |
type | string | “COUPON” | ”BANNER” | ”NOTICE” | Type of pop-up |
Sample code
Upon clicking a coupon in the player, a CUSTOM_ACTION
can be defined using a custom payload object as follows.
This is an example of how to manually handle the event using the custom payload object when the CUSTOM_ACTION
event occurs. The custom payload object is defined in the pop-up edit window as {"coupon": "12341234", "url": "https://shoplive.cloud/sample_coupon"}.
Basic
CUSTOM_ACTION: function (payload) {
// customPayload is object of customized payload
var customPayload = payload.payload;
window.open(customPayload.url); // Open link with new window
alert(customPayload.coupon + " coupon!"); // Coupon code alert
const player = cloud.shoplive.getPlayer();
player.sendMessage("removeCoupon"); //Dismiss coupon
}
If you need a coupon copy function to the clipboard, you can define DOWNLOAD_COUPON
as shown in the sample below.
Copy coupon code to clipboard
<script type="text/javascript" src="https://static.shoplive.cloud/shoplive.js"></script>
<script>
// GLOBAL MessageCallback FUNCTION
var messageCallback = {
DOWNLOAD_COUPON: function(payload) {
// get Current Player
var player = cloud.shoplive.getPlayer();
// if, ONAIR player
if(player.campaignStatus === 'ONAIR' && player.campaignKey === payload.campaignKey) {
// copy to clipboard
var textarea = document.createElement("textarea");
document.body.appendChild(textarea);
textarea.value = payload.coupon;
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
// Show Dialog
player.sendMessage('showDialog', {title: 'Copy to clipboard completed.', message: payload.coupon });
}
}
}
cloud.shoplive.init({ accessKey: 'YOUR ACCESS KEY HERE', messageCallback: messageCallback });
</script>