Table of Contents

How to redirect visitors to a URL (web only)

Jonathan Goodfellow Updated by Jonathan Goodfellow

You may want to direct your user to an external URL at some point during your flow. In this article, let's explore the different ways we can do this!

  1. Create a send message block with the text for the link
  2. Select the text you want to be a hyperlink

  1. Select the link option

  1. A text input will be displayed. Type the url where you'll want a new tab to be opened and press the check option
  2. Now you will see the text with the link in blue

  1. You can use Landbot Fields too:


If you are planning to use Fields, and expect that the value of the Field might contain spaces or other special characters, make sure to use the Encode() method with the Formula block before using the Fields in the redirection, otherwise the URL might fail.

  1. In case you want to customize with HTML, you can do something like this:

Check this <a href="@{newurl}" target="_blank">link</a>

Here @newurl is the link where we want the user to be redirected

Same tab URL jump

You can use this method when you want the user to be directed to an external URL in the same browser tab as your agent.

  1. First, we will create with a Set a Field the URL where we want to redirect the user:
Be sure not to use the Field @url as it's a Landbot system variable

  1. This step is optional, but it's good practice to tell the user that they're going to be redirected:

  1. Then we use a Code block that will trigger the redirection function:

Here is the code:

window.location.href="@new_url"

Other custom solutions:

With 5 seconds (5000 milliseconds) of delay before redirection:

setTimeout(()=>{window.location.href = "@new_url"}, 5000

Open a new tab (this method might be restricted by some browsers):

window.open("@new_url", "_blank");

Goodbye Message Block

You can use the Goodbye Message Block to redirect your user to an external URL at the end of their chat session:

  1. Create a Goodbye Message Block
  2. Turn on the "Redirect to URL" option and add the URL

  1. Set a redirect message that will display to the user, and choose the length of the countdown before the redirection:

You can use Landbot Fields too:



As with the URL redirects in the Send a Message Block, if you are planning to use Fields, and expect that the value of the Field might contain spaces or other special characters, make sure to use the Encode() method with the Formula block before to use the Field in the redirection, otherwise the URL might fail.

Special redirections:

With redirections you can do more than just redirect to another url, here are some examples:

  • Link to Call phone number:

Instead of a regular url:

https://landbot.io

Use

tel:+3411223344

or with Fields:

tel:@{phone}

  • Send Email

Instead of a regular URL:

https://landbot.io

Use

mailto:feedback@landbot.io

or with Fields:

mailto:@{email}

  • WhatsApp message:

Instead of a regular url:

https://landbot.io

Use

https://api.whatsapp.com/send?phone=34123123123

or with Fields:

https://api.whatsapp.com/send?phone=@{phone}

  • Redirect user to PDF:

In this case, it's simple, just use the URL where the file is hosted, like this:

https://www.ikea.com/es/en/files/pdf/eb/42/eb42a602/cocinascolor-19-hfb-07-esp_1.pdf

Template

You can check out this template to see the setup and how web redirects with code work in a bot.

Just click here

Was this article helpful?

How to add a Click-to-Call/Email/WhatsApp button

Contact