Home > How to: Hide the chat button on a page

Categories:


(Last Updated On: April 11, 2023)

About This Article

This article explains how to hide the chat button on a page.

If you want to hide the SnapEngage chat button on certain pages of your site, you will need to add some code to your SnapEngage code snippet. Below is the code you need to use.

Don’t forget to replace the placeholder widget ID with your own widget ID, and insert the strings (words) of the page URLs you want to hide the chat button on. Each string needs to have quotation marks around it, and have a comma at the end.

Note: When you check to make sure the new code is working, please try in an incognito/private window, or clear your browser cache and cookies. This will work for any type of website, including WordPress.

<! — begin SnapEngage code — >
<script type=”text/javascript”>

(function () {
var se = document.createElement(‘script’);
se.type = “text/javascript”;
se.async = true;
se.src = ‘//storage.googleapis.com/code.snapengage.com/js/xxx-xxx-xxx-xxx.js’;
var done = false;
se.onload = se.onreadystatechange = function () {

if (!done && (!this.readyState || this.readyState === ‘loaded’ || this.readyState === ‘complete’)) {
done = true;

/* Place your SnapEngage JS API code below */

// This will block the button from appearing on any/all URLs that CONTAIN the following strings
// This is useful if you want to block the chat button from appearing on all sub-pages beneath a target word.
// Example: Using “tree” would block
// ‘https://www.example.com/tree/acacia” and “https://www.example.com/tree/redwood’
// but it would also block
// ‘https://www.example.com/street/glennwood’
// because “street” CONTAINS the string “tree”
// NOTE: The more specific you can make these, the better
var partUrlToHideButton = [
‘example.com/no-chat-page’,
‘/secret-pages’,
‘login’,
];

// The button will be hidden ONLY if the URL EXACTLY matches these strings
// This is useful if you want to block the chat button from appearing on
// ‘https://www.example.com/page/sub-page’,
// but not
// ‘https://www.example.com/page/sub-page/sub-sub-page’
var exactUrlToHideButton = [
‘https://exact-url-to-block.com’,
‘https://other-exact-url-to-block.com’,
];

var url = window.location.href;

function hideChatButtonOnThisPage() {
SnapEngage.hideButton();
SnapEngage.setCallback(‘Close’, function (type, status) {
SnapEngage.hideButton();
});
};

partUrlToHideButton.forEach(function (partUrl) {
if (url.indexOf(partUrl) !== -1) {
hideChatButtonOnThisPage();
}
});

exactUrlToHideButton.forEach(function (exactUrl) {
if (url === exactUrl) {
hideChatButtonOnThisPage();
}
});
}
};

var s = document.getElementsByTagName(‘script’)[0];
s.parentNode.insertBefore(se, s);
})();

</script>

<!– end SnapEngage code –>

Did you find this article helpful?

Not HelpfulNeeds WorkSo-soHelpfulVery Helpful (9 votes, average: 2.56 out of 5)
Loading ... Loading ...

Published May 19, 2017