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;
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.
- Add the following code in a Message block, in the moment of the flow where we want to redirect the user:
- 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):
window.location.href = "https://www.landbot.io"
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.
- 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.
- 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:
- 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.
window.location.href = url