Excluding your chat widget on certain pages of your website

Justin Maxwell Updated by Justin Maxwell

Problem

You've installed the Smith.ai Chat widget on your website, but you don't want it to appear on specific pages. For example, certain areas of your website may drive an abnormal amount of bad leads (e.g., high SEO pages for people just seeking information), wasting your time.

Solution

Instead of using the JavaScript snippet provided in your chat account, you'll need to modify things a bit. Find your code and paste it into a notepad editor. There are a few things we'll need:

  • Your specific chat ID (we'll show you how to find this)
  • The addresses of the pages you'd like to exclude
  1. Find your Chat ID and keep this handy. We will refer to this as $ChatID.
  2. Find the addresses of the page(s) you want to ignore and paste them into your text document
  3. Then delete everything from "https://" through the first slash for each of them
  4. Ok, so at this point, you should have your $ChatID and the paths of any pages you want to exclude. Now, copy and paste this into your document:
<script type="text/javascript">
var excludePagePaths = [
"page1",
"page2"
];
var showWidget = true;
for (var int = 0; int < excludePagePaths.length; int++) {
if (window.location.pathname.includes(excludePagePaths[int])) {
showWidget = false;
break;
}
}
if (showWidget == true) {
// show the smith.ai widget
window.SMITH={},window.SMITH.smithChatAccount="$ChatID"; var script=document.createElement("script"); script.async=!0, script.type="text/javascript",script.src="https://app.smith.ai/chat/widget-latest.js",document.getElementsByTagName("HEAD").item(0).appendChild(script);
}
</script>
  1. Replace $ChatID with your actual Chat ID.
  2. This next part is a bit trickier. You're going to wrap each page in quotes and put a comma after each except for the last one. Like:
    "page1",
    "page2",
    "page3",
    "page4"


    (notice the last one does not have a comma)

    or in our case:

    "versus/ruby-receptionists",
    "blog/the-top-5-mistakes-small-business-owners-make-with-their-ivr"
  3. Ok, assuming you did everything, You'll now have a chunk of code like this. BUT NOT THIS, because if you just copy and paste ours, it won't do anything.
<script type="text/javascript">
var excludePagePaths = [
"versus/ruby-receptionists",
"blog/the-top-5-mistakes-small-business-owners-make-with-their-ivr"
];
var showWidget = true;
for (var int = 0; int < excludePagePaths.length; int++) {
if (window.location.pathname.includes(excludePagePaths[int])) {
showWidget = false;
break;
}
}
if (showWidget == true) {
// show the smith.ai widget
window.SMITH={},window.SMITH.smithChatAccount="a1234b56-cd78-90ef-abcd-a1b23cd456ef"; var script=document.createElement("script"); script.async=!0, script.type="text/javascript",script.src="https://app.smith.ai/chat/widget-latest.js",document.getElementsByTagName("HEAD").item(0).appendChild(script);
}
</script>
  1. Now, replace the javascript widget on your live site with your new shiny context-sensitive javascript!

Questions? Contact us!

If you're already a Smith.ai client and need help, please email us at support@smith.ai or call us at (650) 727-6484 for assistance.

If you're not yet a Smith.ai client, please schedule a free consultation to get started with our live chat or email us at sales@smith.ai. We'll help you select the best plan to match your business’s growth goals and budget.

How did we do?

Can I change the URL of the stand-alone chat widget?

How to Install your Chat Widget

Contact