Summary

This guide explains how to configure a chatbot in Wati to collect UTM (Urchin Tracking Module) parameters and store them as contact attributes. This setup helps you track where leads and conversations are coming from by automatically capturing UTM data during customer interactions.

By the end of this setup, your chatbot will:

  • Automatically trigger through a Keyword Action

  • Collect UTM parameters from incoming messages

  • Store the collected values in contact attributes

Instructions

Add UTM parameters to Wati chat widget script

Add the below script to your HTML file after the import script.

  • Where to place it: Insert the following code inside the <body> tag, preferably just before the closing </body> tag.

Important:

  • Make sure the chat widget script includes the required UTM parameters so Wati can capture and track them correctly.

  • The parameters defined in the trackingData section in the script below are sample values for reference and can be customized based on your setup and the UTM parameters you want to track.

  • Before proceeding, make sure to review the full guide for adding a chat widget to your website, including UTM tracking.

Here's the sample script for your reference:

<script>
window.onload = function () {
// Define your tracking parameters.
// Replace these with your actual UTM and custom parameters.
//
// You can obtain these parameters from:
// 1. URL parameters
// 2. localStorage
// 3. Browser cookies
// 4. Static campaign values

var trackingData = {
utm_source: "google",
utm_medium: "cpc",
utm_campaign: "spring_sale",
pr_prod_strat: "e5_desc",
pr_rec_id: "9c7af79a0",
pr_rec_pid: "9827376955687",
pr_ref_pid: "9827375939879",
pr_seq: "uniform",
};

// Compress and encode the tracking data
var compressedParams =
CrossPlatformCompressor.encode(trackingData);

// Initialize the Wati WhatsApp widget
WatiWidget.CreateWhatsappChatWidget({
brandSetting: {
// Your WhatsApp number
phoneNumber: "18129934041",

// Default message with encoded tracking parameters
messageText: `Hello,\nI have a question about https://test_website.\n\n[ContextId: ${compressedParams}]`,
},
});

// Note:
// "ContextId" must match the keyword configured
// in the Wati Automation module.
};
</script>

Create a Chatbot to track UTM parameters

Step 1: Create a new chatbot

  • Go to Automation > Chatbot in your Wati environment.

  • Click Add Chatbot.

  • Enter a name for the chatbot.

  • Click Add.

Step 2: Add the Collect UTM node

  • Inside the chatbot builder, locate the node type Collect UTM.

  • Add the Collect UTM node to the chatbot flow.

  • Click the newly added node.

A popup window will appear with a keyword input field.

  • Enter a keyword of your choice.

Important: Save this keyword, as you will need it later when setting up the Keyword rule.

  • Click Save.

Collect UTM V2 Chatbot node

The Collect UTM V2 node is currently in Beta and is available to WATI customers on Pro and Business plans. It must be enabled for your account by our Support team.

To request access and start using the Collect UTM V2 node to collect UTM parameters, contact our Support team.

Before using the node, keep the following points in mind:

Message Format

When users click the Chat with us button, the message sent to WhatsApp must include the UTM parameters in a specific format so the Collect UTM V2 node can read and extract them.

The message should follow this format:

Hello, 

I have a question about https://test_website.

UTM_keyword [utm_source:google&utm_medium:cpc&utm_campaign:xyz]

Key Components:

  • Keyword: UTM_keyword is the keyword used to start the chatbot. Although the Collect UTM V2 node ignores the keyword when extracting UTM parameters, it must match the keyword configured in the Keyword Action rule.

  • Square brackets [ ]: The UTM parameters must be enclosed in square brackets. The node reads the content between the first opening square bracket ([) and the last closing square bracket (]).

  • UTM parameters: Each parameter must use a colon (:) between its name and value. Use an ampersand (&) to separate multiple parameters.

Important Notes

Keyword configuration:

  • Configure the same keyword in the Keyword Action rule and the WhatsApp widget message.

  • Set the Keyword Action matching condition to Contains, not an exact match, because the incoming message includes additional text.

  • Keyword matching is case-insensitive.

  • Use a unique keyword to avoid conflicts with other Keyword Action rules. For example, a generic keyword such as hello could match another rule that fires before your intended rule.

Message format:

  • Read the UTM parameters from the current page URL and include them in the WhatsApp widget message.

  • Use the format [parameter_name:parameter_value&parameter_name:parameter_value].

  • Do not use square brackets ([ or ]) anywhere else in the message. The node reads from the first opening bracket to the last closing bracket.

  • Values must not contain an ampersand (&), as the node uses it to separate parameter pairs. A colon (:) within a value is allowed.

  • The node saves values exactly as they are received. Send readable values instead of URL-encoded values. For example, use utm_term:test website instead of utm_term:test%20website.

  • The Collect UTM V2 node does not decode encoded values.

  • Sending only the page URL with UTM parameters will not work because URL parameters use = instead of the required : format and are not enclosed in square brackets.

  • Sending an encoded string, such as [ContextId: encoded_string], will not extract individual UTM parameters. The node will treat it as a single value.

Troubleshooting

If the Collect UTM V2 node does not find any valid UTM parameter pairs in the incoming message, the chatbot stops at that node.

Check that:

  • The message contains valid parameter-value pairs inside square brackets.

  • Each parameter name and value are separated by a colon (:).

  • Multiple parameters are separated by an ampersand (&).

  • The message does not contain additional square brackets.

  • The values do not contain ampersands (&).

Step 3: Add the Update Attribute node

  • Locate the node type Update Attribute.

  • Add the node to the chatbot flow.

  • Click the newly added node.

A popup window will appear with fields for attribute configuration.

Configure the fields

You must configure the following 2 fields:

Field

Value

Left field

collect_result

Right field

@collect_result

Tip: You can search using the keyword collect to quickly locate these values.

  • Click Save.

Complete the chatbot flow setup

Before saving the chatbot, make sure the following configuration is completed:

  • The CollectUTM node is set as the starting step.

  • The CollectUTM node is connected to the Update Attribute node.

After confirming the setup:

  • Click Save to save the chatbot.

Step 4: Create a new Keyword rule

Add the keyword rule to trigger the chatbot

  • Go to Automation > Rules.

  • Click + Create Rules.

Select a trigger

Choose the event that should start the automation.

  • For WhatsApp messages, select New WhatsApp message is received.

The trigger determines when Wati should evaluate the rule.

Add a keyword filter

Next, define the keywords that should activate the rule.

  • Under Filters, select Incoming message matches keyword(s).

  • Choose Contains as the matching method.​

  • Add the keyword we created earlier in this guide: collectUTM.

Important: The keyword must match the keyword configured in the CollectUTM node. Keyword matching is not case-sensitive.

Add an action (automated response)

Now define what should happen when the keyword is detected.

  • Go to the Actions section.

  • Choose Start chatbot as the action.

  • Select the chatbot you just created earlier.

Activate and save the rule

Once your configuration is complete:

  • Enter the name for your rule (if you haven't already).

  • Turn the rule On.

  • Click Save changes.

Result

Your UTM collection setup is now complete. When the configured keyword is triggered, the chatbot will:

  • Collect UTM parameters from the conversation

  • Store the collected data in the contact attribute

  • Allow you to use the captured UTM data for tracking and reporting purposes

Frequently Asked Questions (FAQs)

UTM tracking setup

1. How does Wati collect and store UTM parameters using a chatbot?

Wati uses a chatbot with a Collect UTM node to capture UTM parameters from incoming WhatsApp messages. The chatbot extracts the UTM values and stores them in a contact attribute using the Update Attribute node. A Keyword Action rule triggers the chatbot when the configured keyword is detected.

2. How do I configure the Wati chat widget to send UTM parameters?

Add the UTM tracking script to your website's HTML file inside the <body> tag, preferably just before the closing </body> tag. The script must include the required UTM parameters in the trackingData section and pass the tracking data through the WhatsApp widget message.

The tracking parameters can be obtained from URL parameters, localStorage, browser cookies, or static campaign values. Customize the sample tracking values based on the parameters you want to track.

3. What are the requirements for using the Collect UTM V2 chatbot node?

The Collect UTM V2 node is currently in Beta and is available to Wati customers on Pro and Business plans. The node must be enabled for your account by the Wati Support team. Contact Support to request access.

The WhatsApp widget message must include UTM parameters in the required format so the node can extract them. The parameters must be enclosed in square brackets, with a colon (:) separating each parameter name and value and an ampersand (&) separating multiple parameter-value pairs.

4. What message format does the Collect UTM V2 node support?

The incoming WhatsApp message must follow this format:

Hello, 
I have a question about https://test_website.
UTM_keyword [utm_source:google&utm_medium:cpc&utm_campaign:xyz]

The message must follow these rules:

  • The keyword must match the keyword configured in the Collect UTM node and Keyword Action rule.

  • UTM parameters must be enclosed in square brackets ([ ]).

  • Separate each parameter name and value using a colon (:).

  • Separate multiple parameter-value pairs using an ampersand (&).

  • Do not use additional square brackets elsewhere in the message.

  • Values must not contain ampersands (&).

  • Values can contain colons (:).

  • Send readable values instead of URL-encoded values because the node does not decode encoded values.

Sending only a page URL with UTM parameters or an encoded tracking string will not extract individual UTM parameters.

5. Why is the Collect UTM V2 node not extracting UTM parameters?

The Collect UTM V2 node may fail to extract parameters if the incoming message does not contain valid parameter-value pairs in the required format. If no valid pairs are found, the chatbot stops at the Collect UTM V2 node.

Check that the incoming message contains square brackets around the UTM parameters, uses colons (:) between parameter names and values, and uses ampersands (&) to separate multiple parameters. Also, make sure the values do not contain ampersands and that the message does not contain additional square brackets.

Keyword rule and chatbot configuration

6. What keyword should I configure to trigger the UTM tracking chatbot?

Use the same unique keyword in the Collect UTM node, the WhatsApp widget message, and the Keyword Action rule. The Keyword Action matching condition must be set to Contains, not an exact match, because the incoming WhatsApp message includes additional text.

Keyword matching is case-insensitive. Use a unique keyword to avoid conflicts with other Keyword Action rules. Generic keywords such as hello may trigger another rule before the intended rule.

7. How should I configure the Update Attribute node to store collected UTM parameters?

Configure the Update Attribute node with the following values:

  • Left field: collect_result

  • Right field: @collect_result

The Collect UTM node must be the starting step in the chatbot flow and must be connected to the Update Attribute node. This configuration stores the collected UTM data in the contact attribute.

8. What happens after the UTM tracking chatbot and Keyword Action rule are configured?

When a customer sends a WhatsApp message containing the configured keyword and valid UTM parameters, the Keyword Action rule triggers the chatbot. The chatbot collects the UTM parameters and stores the captured data in the contact attribute.

You can then use the collected UTM data for lead source tracking and reporting.

Did this answer your question?