How to launch a Landbot by clicking a button

Ana Updated by Ana

Here below you can find the code you need to trigger and open your landbot, embedded as a LiveChat or Pop up mode, by clicking a button.

<html> 
<body>
<div id="wrapper">
<button class="openbot">Open Bot</button>
</div>

<script SameSite="None; Secure" src="https://cdn.landbot.io/landbot-3/landbot-3.0.0.js"></script>
<script>
var myLandbotpop = new Landbot.Popup({
configUrl: 'https://chats.landbot.io/v3/H-642181-Q42D49PVMDCXYYL8/index.json'
});

var buttonOpen = document.getElementsByClassName("openbot")[0];
buttonOpen.addEventListener('click', (event) => {
event.preventDefault();
myLandbotpop.open()
});
</script>
</body>
</html>

To hide the widget, you must add the code below in the Design > Custom Code > Add CSS section of your bot:


.LivechatLauncher{
display: none
}

How did we do?

Set the flow depending on the url path (for embedded landbots)

Open LiveChat bot as soon as page loads

Contact