Sample code
- Print
Sample code
- Print
Article summary
Did you find this summary helpful?
Thank you for your feedback
Override the actions for events such as
DOWNLOAD_COUPON
,CLICK_PRODUCT
, andLOGIN_REQUIRED
using themessageCallback
.Display broadcasts and listings on the screen using the Shoplive Plugin.
Sample code
<html>
<head>
<title>Shoplive - Simple Shoplive Plugin example</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover, shrink-to-fit=no"
/>
<script
type="text/javascript"
src="https://static.shoplive.cloud/shoplive.js"
></script>
<script>
let 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,
});
}
},
CLICK_PRODUCT: function (payload) {
// You can add a new parameter to the URL of the clicked product.
var url = payload.url + "¶meter=" +"{your_parameter}";
// The product page will be opened in the current window.
location.href = url;
},
LOGIN_REQUIRED: function (payload) {
alert("LOGIN_REQUIRED");
location.href = "YOUR_LOGIN_PAGE_URL";
},
};
cloud.shoplive.init({
accessKey: "{YOUR_ACCESS_KEY}",
messageCallback: messageCallback,
});
let userId = "USER_ID";
let userName = "USER_NAME";
if (userId) {
cloud.shoplive.setUserObject({ userId: userId, userName: userName });
}
</script>
</head>
<body>
<div id="shoplive-overall-area"></div>
<script defer>
cloud.shoplive.setOverall("shoplive-overall-area");
</script>
</body>
</html>