Send variables from your page (the container site) to your embedded Landbot

We might want to send variables from our site to the bot to continue the conversation, or keep track of a special token.

In this example we will use LiveChat embed and we will have a couple of values like name and email

  1. In the code we use to embed the bot in the container site we will add the following code, as in the picture below:

In this case nameVar and emailVar are the values that will be ready in the site before the bot is loaded, and will be in the same scope as in the following script:

<script> myLandbot.on('landbot-load', () => { 
myLandbot.send('containerVariables', {
'name':nameVar,
'email':emailVar
})
})
</script>

Bare in mind that in this case we added 'name' and 'email' that will be the names of the variables inside the bot

  1. Inside the bot, we will add a listener that will pass the variables. So we go to the Design / Advanced / Add JS section like in the picture below and add the following code:

<script>
Landbot.on('containerVariables', (data) => {
Landbot.exec('landbot-custom-data', data)
})
</script>

  1. Now, if we want to display such variables, we will be able to do it. Only after the Welcome Message!

Demo:


How did we do?