Skip to content

Instantly share code, notes, and snippets.

@KixPanganiban
Created April 29, 2022 13:49
Show Gist options
  • Save KixPanganiban/3f4fcf205ab013daef28bb9aa4e6508a to your computer and use it in GitHub Desktop.
Save KixPanganiban/3f4fcf205ab013daef28bb9aa4e6508a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Custom handoff from Ada to Provide Support Sample</title>
<style>
.show-button {
display: block !important;
}
#ada-button-frame {
display: none;
}
/**
* Note: these clases are unique to each Provide Support implementation.
* This example uses the Provide Support button's parent div and anchor classes.
*/
.psmtc_yQcq .chat-button-yQcq {
display: none;
}
</style>
</head>
<body>
<script>
let adaButton;
function setLastChatOpened(name) {
sessionStorage.setItem("lastChatOpened", name);
}
function hideAda() {
adaEmbed.getInfo().then(function (info) {
if (info.isChatOpen === true) {
adaEmbed.toggle();
adaButton.classList.remove("show-button");
}
});
}
function checkLastChatOpened() {
let lastChatOpened = sessionStorage.getItem("lastChatOpened");
if (lastChatOpened === "ps") {
startPS();
} else {
adaButton.classList.add("show-button");
}
}
function startPS(fields) {
function n(n, e) {
e = document.createElement("script");
(e.src = "https://image.providesupport.com/" + n),
document.body.appendChild(e);
}
// The following path is subject to change. Check the Provide Support chat button codes.
n(
"js/1a77itzhy4zm11vnelu1t3739w/safe-standard-sync.js?ps_h=yQcq&ps_t=" +
Date.now() +
fields
),
n("sjs/static.js");
const checkPS = setInterval(function () {
if (window.psOpenWindow) {
psOpenWindow();
// Note: these clases are unique to each Provide Support implementation.
document.querySelector(".psmtc_yQcq .chat-button-yQcq").classList.add("show-button");
setLastChatOpened("ps");
hideAda();
clearInterval(checkPS);
}
}, 100);
}
window.adaSettings = {
adaReadyCallback: () => {
adaButton = document.querySelector("#ada-button-frame");
checkLastChatOpened();
},
eventCallbacks: {
custom_handoff: (event) => {
const first_name = event.user_data.global.first_name;
const email = event.user_data.global.email;
const fields = `&first_name=${first_name}&email=${email}`;
startPS(fields);
},
},
};
</script>
<script
id="__ada"
data-handle="ada-example"
src="https://static.ada.support/embed2.js"
></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment