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

How did we do?

How to embed Google Maps addresses in an iframe

Launching a bot depending on browser language

Contact