Skip to main content

How to capture and store UTM parameters in Wati

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.

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)

Overview

1. What does this UTM setup in Wati do?

This setup allows Wati to collect UTM (Urchin Tracking Module) parameters from conversations, store them as contact attributes, and use the data for tracking and reporting purposes.

2. What happens after the UTM collection setup is completed?

After the setup is completed, the chatbot can:

  • Automatically trigger through a Keyword Action

  • Collect UTM parameters from incoming messages

  • Store collected UTM values in contact attributes

Chat Widget Script Setup

3. Where should the Wati chat widget script be added in the HTML file?

The Wati chat widget script should be added inside the <body> tag, preferably just before the closing </body> tag.

4. Why should UTM parameters be included in the chat widget script?

UTM parameters must be included in the chat widget script so Wati can capture and track them correctly.

5. Can the parameters in the trackingData section be customized?

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

6. What does the ContextId value in the script represent?

The ContextId value in the script must match the keyword configured in the Wati Automation module.

Chatbot Setup

7. What chatbot flow configuration is required before saving the chatbot?

Before saving the chatbot:

  • The CollectUTM node must be configured as the starting step.

  • The CollectUTM node must be connected to the Update Attribute node.

Keyword Rule Setup

8. Is keyword matching case-sensitive in the Keyword rule setup?

No. Keyword matching in the Keyword rule setup is not case-sensitive.

Did this answer your question?