Table of Contents

Detect if bot was opened

Abby Updated by Abby

Sometimes we may want to detect if the chatbot was opened, even if the client didn't interact

This will give us some insight into how many users start to interact and don't complete the interaction

In order to do this we just need a Javascript snippet, this snippet sets a variable in your page when the bot was opened, if the bot is never opened the variable is never set and will be undefined, if the chatbot is opened, regardless of whether the client interacts, our variable will be set to True

How you use the variable is ultimately up to you!

Here's what we need to add to our embed page, we'll add it directly under the embed script, before the closing script tag (</script>):

let userOpened;
function botOpen(){
if (document.getElementsByClassName('is-open')[0]){
userOpened = true;
console.log('is opened')
}
else {
setTimeout(botOpen, 2000);
}
}
botOpen();

We'll then have the variable userOpened available to us.

Count how many users opened the bot

We can use userOpened variable to count how many users open the bot. We provide a guide below, but the concrete implementation will need to be done with a developer taking into account your own use case and your website configuration.

To track how many times the chatbot has been opened, you can utilize a global variable to maintain a count. This variable can be incremented each time the chatbot opening is detected. Additionally, you can store this count in the browser's localStorage to ensure persistence even if the user refreshes the page. If you require this information to be centralized on a server, you can achieve this by sending the data to your server through an API call.

How did we do?

Conditional Welcome: Direct the Flow of Your Bot Based on External Parameters

Customized Behavior in Mobile Browsers

Contact