Dynamic Chatbot Configuration

How to dynamically configure different chatbots based on page URL

Display different chatbots on different sections of your website using JavaScript to dynamically select which chatbot loads based on the current URL. This allows you to provide specialized support for different user segments or website sections.


Why Use Dynamic Configuration?

  • Specialized Support: Show product-specific chatbots on product pages

  • User Segmentation: Display different chatbots for members vs. visitors

  • Multi-language Support: Load language-specific chatbots automatically

  • Single Script: Manage multiple chatbots with one embed code


Implementation Script

<script defer>
    // Create the Wonderchat script element
    var wcs = document.createElement("script");
    wcs.setAttribute("data-name", "wonderchat");
    wcs.setAttribute("data-address", "app.wonderchat.io");
    
    // Get the current page path
    var path = window.location.pathname;
    
    // Configure different chatbots based on URL patterns
    if (/^\/members\/[^/]+/.test(path)) {
        // Members area - use specialized chatbot
        wcs.setAttribute("data-id", "YOUR_MEMBERS_CHATBOT_ID");
    } else if (path.startsWith("/support/")) {
        // Support section
        wcs.setAttribute("data-id", "YOUR_SUPPORT_CHATBOT_ID");
    } else if (path.startsWith("/products/")) {
        // Products section
        wcs.setAttribute("data-id", "YOUR_SALES_CHATBOT_ID");
    } else {
        // Default - general chatbot
        wcs.setAttribute("data-id", "YOUR_GENERAL_CHATBOT_ID");
    }
    
    // Set script source and widget configuration
    wcs.setAttribute("src", "https://app.wonderchat.io/scripts/wonderchat.js");
    wcs.setAttribute("data-widget-size", "normal");
    wcs.setAttribute("data-widget-button-size", "normal");
    
    // Append the script to the page
    document.body.appendChild(wcs);
</script>

Setup Steps

1. Get Your Chatbot IDs

  • Log in to your Wonderchat dashboard

  • Find each chatbot you want to use

  • Copy the chatbot ID from the embed code or settings

  • Example ID: cm1hzlrdz04bthxcy5b849lma

2. Plan Your URL Structure

Decide which chatbot appears where:

  • / β†’ General support chatbot

  • /members/* β†’ Members-only chatbot with account-specific knowledge

  • /support/* β†’ Technical support chatbot

  • /products/* β†’ Sales chatbot with product information

3. Implement the Script

  • Copy the script above

  • Replace all YOUR_*_CHATBOT_ID placeholders with actual IDs

  • Modify the URL patterns to match your site structure

  • Add the script to your website template before </body>

4. Test Your Implementation

  • Visit different sections of your website

  • Verify the correct chatbot loads on each page

  • Test the chatbot functionality


Common URL Patterns

Members Area

Language-Based

Subdomain-Based

Multiple Conditions


Advanced Configuration

Dynamic Widget Sizing

Page-Specific Positioning


Troubleshooting

Chatbot not appearing?

  • Verify the chatbot ID is correct (check for typos)

  • Ensure the chatbot is active in your dashboard

  • Check browser console for JavaScript errors

  • Confirm the script is loading (check Network tab)

Wrong chatbot loading?

  • Add console.log(path) to debug which path is detected

  • Check your URL patterns match exactly (remember leading slashes)

  • Test patterns in order - more specific patterns should come first

Multiple chatbots appearing?

  • Remove any existing static Wonderchat embed codes

  • Ensure this script only loads once per page


For additional support, contact us at [email protected]

Last updated

Was this helpful?