Useful Tip: How to Reduce AI Chatbot Message Views and Token Burn

Every time a user bounces or a bot hits your page, your embedded AI Chatbot widget loads anyway—wasting your precious monthly views and message token quotas.

The lightweight script provided below acts as a smart AI Chatbot widget gatekeeper. Instead of loading the Elfsight AI Chatbot widget instantly, it holds off until a visitor is actually engaged. It triggers the widget only after a user scrolls through 50% of the page or stays active for 30 seconds.

To set this up, just add the code below to your website as an HTML snippet using a plugin like Code Snippets or WPCode, and configure it to load in the Site Wide Footer. (Make sure to replace WIDGETID with your actual Elfsight widget ID)

It’s a quick fix to stop accidental triggers and keep your quota usage under control.

Enjoy!


<div class="elfsight-app-WIDGETID" data-elfsight-app-lazy></div>

<script>
(function() {
    // Configuration: Target the specific widget container
    var widgetContainer = document.querySelector('.elfsight-app-WIDGETID');
    if (!widgetContainer) return;

    var widgetLoaded = false;

    // Core Logic: Function to inject the Elfsight script dynamically
    function loadElfsightWidget() {
        if (widgetLoaded) return;
        widgetLoaded = true;
        var script = document.createElement('script');
        script.src = 'https://elfsightcdn.com/platform.js';
        script.async = true;
        document.body.appendChild(script);
    }

    // Trigger 1: Automatic load after 30 seconds
    setTimeout(loadElfsightWidget, 30000);

    // Trigger 2: Load on scroll (when the user reaches 50% of the page)
    window.addEventListener('scroll', function() {
        var scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
        var scrollPosition = window.scrollY;
        if ((scrollPosition / scrollHeight) >= 0.5) {
            loadElfsightWidget();
        }
    });
})();
</script>
1 Like