Code Examples for Common Widget Integrations on Your Web Page

In this article, you'll find a collection of practical, ready-to-use code snippets designed to help you customize your widget installations based on various user interactions and scenarios.

Each section below details a specific use case, accompanied by the corresponding code that you can directly copy and paste for immediate implementation.

Custom Widget Initialization

On Button Click

<!DOCTYPE html>
<html>
<head></head>
<body>
    <button id="widget-loader">Load Widget</button>
    <script>
        var widget_loaded = false;
        document.getElementById("widget-loader", function(event) {
            // Prevent double loading
            if (!widget_loaded) {
                widget_loaded = true;
                // Load the widget
                const project_token = "PROJECT_TOKEN";
                const script_tag = document.createElement("script");
                script.src = "https://platform.indigo.ai/widget.js?token=" + project_token + "&v=3";
                document.body.appendChild(script);
            }
        })
    </script>
</body>
</html>

After a Specified Time Delay

On Scroll to a Specific Element

Interacting with the Widget

Opening the Widget After a Delay

Page Actions Triggered by Events

Actions Triggered by an Answer

An interesting scenario to consider is triggering a modal when a specific response is activated in the bot.

For example, consider a situation where you want to prompt user registration after a series of message exchanges culminates in the bot delivering a registration response. In such cases, we can utilize the $answer event to catch this response and initiate corresponding actions.

triangle-exclamation

Google Analytics

A common setup involves linking Google Analytics to track when the chat opens. Here's how you can structure the widget installation for this purpose:

Last updated

Was this helpful?