Last updated: 23 June 2021

This tutorial guides you through the process of extracting and storing a URL parameter’s value inside a variable, for later use inside the chatbot’s content or integrations.

Before going through this tutorial, it is worth familiarising yourself with formatters.

Step 1: Host your chatbot on a live URL

To extract a parameter value, your chatbot must be hosted on a live website URL.

This tutorial works for the widget channel only.

Step 2: Identify the parameter

Head over to the page where your chatbot is hosted.

Observe the URL and identify the value you would like to extract and the parameter that contains it. It should look something like this:

Some common parameters are:

  • ?id=

  • ?token=

  • ?utm_source=

For the purpose of this tutorial, let’s assume you would like to extract and store the value from a utm_source parameter. The utm_source parameter typically gives you an indication of where the user came from before landing on your page, with values such as TechCrunch or Inc.com.

You can use this value to tweak your chatbot’s message and make it more contextual. For instance, instead of saying:

Hello, welcome to the XYZ chatbot.

It could say:

Hello there, welcome to the XYZ chatbot. I see you come from TechCrunch – one of our favourite news outlets!

Step 3: Create your variable

To allow us to extract the parameter’s content, we will need to store it inside a variable.

Head to SettingsVariables. Hit Create in the top right.

Give your variable a name and a default value (optional).

Before you save, click Advanced settings.

Within the advanced settings is where we define the rule for

  1. Finding the parameter

  2. Extracting the value

  3. Saving the value inside the new variable

This three step process is easily done using the Copy existing variable feature.

Why ‘copy existing variable’?

Your chatbot platform comes loaded with a handful of default variables, including things like Current time or Subscriber identifier. One of these variables is called chatbot_url.

Within chatbot_url is stored the URL on which the chatbot is hosted and currently being used by the user. For example, as user A is talking to your chatbot on example.com/sales, the chatbot_url variable is example.com/sales. As user B is talking to your chatbot on example.com/hr, its variable is example.com/hr. And so on.

Because we need to extract the value of a parameter attached to the URL the chatbot is currently on, it makes sense to grab the URL stored inside chatbot_url – but not the full URL!

So, we’re going to do some magic and extract the parameter’s value by copying a snapshot of the existing variable into a new one and simultaneously extract the value.

In the Variable field, type {{ to bring up the drop down of available variables. Search for chatbot_url.

In the Formatter field, select Extract URL parameter.

Finally, in the Parameter field, type the parameter you need extracted. In our example, utm_source.

Hit Save. You should see something like this:

Step 4: Edit your welcome conversation

The steps laid out in this tutorial work across any step of any conversation. However, the most likely scenario is to use the parameter information within the very first interaction between your bot and its user.

Thus, we’re going to edit the welcome conversation. More specifically, the first step of the welcome conversation.

Head over to Builder, then open the Welcome conversation.

We need to store the value inside the very first interaction with the chatbot.

Edit the Trigger and add your variable inside Save variables.

We can now use this variable by simply adding it to the copy.