How to redirect visitors to another URL in the same tab (Landbot URL / not embedded)

There are moments when we want to redirect visitors to another URL in our website, for example to let them find out a help article or a product that we want to recommend.

To do so, we have two options to set up a trigger function that at some point of the conversation will redirect visitors to a new URL:

  • redirect to a Fixed URL;
  • redirect to a Variable URL;

Please note that this tutorial is only suitable for bots that are not embedded. To see how to set this for bots embedded, check out this article.

It is not possible to test this tutorial in the Preview mode. Please test in the Share URL mode.

Redirect the visitor to a Fixed URL

If you want to redirect the visitor to the same page, regardless of the flow, you can follow the steps of this option.

  1. Add the following code in a Message block, in the moment of the flow where we want to redirect the user:

Redirecting<script>changeUrl()</script>

  1. In the Design > Advanced > Add JS section of your bot, add the following code, including the URL you want to redirect the visitor to (instead of www.landbot.io):

<script>function changeUrl(){
window.location.href = "https://www.landbot.io"
}</script>

Redirect the visitor to a Variable URL

This second option is useful if you are offering a custom solution for each visitor depending on the flow. That means, if you want to redirect the visitor to different pages, according to the path chosen.

  1. First we are going to set up a variable with the value of the URL we want to redirect the users to.
    Repeat this process, setting the variable for every URL you want to redirect the user to according to the flow.

WARNING: Do not use "url" as the name of this variable. We recommend you use the name @newurl , for example.
  1. Similar to the first example, in the moment where we want to redirect the visitor we are going to add the following code to trigger the change to the specific URL we defined earlier:

Redirecting<script>goTo(@newurl)</script>

  1. In the Design > Advanced > Add JS section of the bot, we will add the function that will make the redirection based on the URL we defined earlier.

    In this case it is not necessary to make any changes to the code, just paste the it into this section and you will be good to go.

<script>function goTo(url){
window.location.href = url
}</script>

Please notice that this code is added in the Design section of your bot. This tutorial does not work using a Code block in the builder section from the bot.


How did we do?


Powered by HelpDocs (opens in a new tab)

Powered by HelpDocs (opens in a new tab)