Table of Contents

Open LiveChat bot as soon as page loads

Ana Updated by Ana

These scripts are valid for both Livechat and Popup embed types

Maybe we want to display the LiveChat as soon as the page is loaded to greet customers, here are three ways to do it, we will always locate the code right after the one we used to embed our bot:

Open bot Always and As Soon As the page is loaded

<script>
myLandbot.onLoad(function() {
myLandbot.open()
})
</script>

Open bot Always and As Soon As the page is loaded in web only

<script>
if (document.body.clientWidth >= 768) {
setTimeout(function() {
myLandbot.open();
}, 400);
}
</script>

Open bot Always and 3 seconds after the page is loaded

<script>
myLandbot.onLoad(function() {
setTimeout(function(){
myLandbot.open()
},3000)
})
</script>

Open bot only to new visitors

<script> 
myLandbot.onLoad(() => {
var visitor = localStorage.getItem('firstvisit')
if (visitor != 'true'){
localStorage.setItem('firstvisit', 'true');
myLandbot.open() } })
</script>

Open bot only to new visitors after 3 seconds

<script> 
myLandbot.onLoad(() => {
var visitor = localStorage.getItem('firstvisit')
if (visitor != 'true'){
localStorage.setItem('firstvisit', 'true');
setTimeout(function(){
myLandbot.open()
},3000) } })
</script>

Open the bot only on specific URLs on your website

This code must be located in the Design > Custom Code > Add JS section of your web bot:

<script>
myLandbot.onLoad(function() {
// Get the current URL
var currentUrl = window.location.href;

// Define an array of URLs that should trigger the bot to open automatically
var openBotUrls = [
"https://www.yourwebsite.com/pageone/index.html",
"https://www.yourwebsite.com/pagetwo/index.html",
// Add more URLs as needed
];

// Check if the current URL is in the list of URLs to open the bot
if (openBotUrls.includes(currentUrl)) {
// Open the chatbot automatically
myLandbot.open();
}
});
</script>

Extra: 'Pop' Sound when bot opens

Applicable only when the user has already interacted with page

To create a sound notification when the bot opens we can add the following to the embed code:

var snd = new Audio('https://codeskulptor-demos.commondatastorage.googleapis.com/pang/pop.mp3');
snd .play();

This code will go in the timeout function

You can add any MP3 as long as it's publicly hosted with a valid url

How did we do?

How to launch a Landbot by clicking a button

Detect if a visitor is on Mobile/Tablet or Desktop

Contact