Open LiveChat bot as soon as page loads (3 ways)

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:

Display bot Always and As Soon As the page is loaded

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

Display 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>

Display bot Always and 3 seconds after the page is loaded

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

Display bot only to new visitors

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

Display 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>

We will always locate the code right after the one we used to embed our bot

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