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

Only for landbots embedded (not standalone). Do not test in Preview mode

We might want to personalise the experience of the visitor to our site with different "chatbots" depending on the section that user is looking at. For example if the visitor is checking your Contact area you might want to offer them to speak live with an agent, or maybe if they are checking the pricing page, you would like to offer them a promotion or just support to select a plan.

Here are the steps for the implementation in the container site and inside Landbot

  1. In the container site where the bot is embedded we need to add the following code, right after the script to embed the bot.

<script> 
myLandbot.on('landbot-load', () => {
myLandbot.send('containerVariables', {
'pathurl':window.location.pathname
})
})
</script>

It will send the path to a Landbot variable, that after the Welcome Message, but to be able to capture it. We need to add the next step in our bot:

  1. Go to the Design / Advance / Add JS and add the following code

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

With this we are creating a Landbot variable (pathurl), that will be available right after the Welcome Message

  1. Now after the Welcome Message block, add a Conditional Block (or as many as you need) to select the flow according to your needs. As you are creating the variable via Javascript, and you want to use it in the Conditional Block, you need to "create" the variable in the editor too when trying to select it

Below you can see it in action:


How did we do?


Powered by HelpDocs (opens in a new tab)

Powered by HelpDocs (opens in a new tab)