Skip to main content
Click to WhatsApp (CTWA) ads on Facebook and Instagram open a WhatsApp conversation when the user clicks. This guide explains how to know if a chat comes from a Meta ad: when the conversation originates from an ad, Jelou automatically injects a _referral object into memory with the source ad’s data. With that information you can attribute the lead, route by campaign, personalize the first reply, or log the source in your CRM—without manually reconciling data between Meta Ads Manager and the conversational channel.

How it works

When a user clicks a Click to WhatsApp ad, WhatsApp opens with a starter message and Meta attaches the ad’s referral data to that first interaction. Jelou detects that data and automatically inserts it into the conversation’s memory under the _referral variable.
No Marketplace installation is required. The _referral object is injected automatically whenever the conversation originates from a Click to WhatsApp ad.

Detecting whether a chat comes from an ad

To know if a conversation arrived from a Meta ad, check whether the _referral variable exists in memory. When the conversation originates from an ad, Jelou inserts the following object:
{
  "_referral": {
    "source_url": "https://fb.me/XXXXX",
    "source_id": "120XXXXXXXXX387",
    "source_type": "ad",
    "body": "BODY_CONTENT",
    "media_type": "video",
    "video_url": "https://www.facebook.com/story.php?story_fbid=XXXXX",
    "thumbnail_url": "https://scontent.ftru6-2.fna.fbcdn.net/v/XXXXXXXXX",
    "ctwa_clid": "CTWA",
    "welcome_message": {
      "text": "WELCOME_MESSAGE"
    }
  }
}
If _referral does not exist in memory, the conversation did not originate from a Click to WhatsApp ad (for example, a user messaging the number directly). Learn more about how to read these variables in: Memory.

Field reference

FieldDescription
source_urlShort URL of the source ad (for example, an fb.me link).
source_idIdentifier of the source ad or post in Meta.
source_typeSource type. The value ad indicates the conversation came from an ad.
bodyMain ad copy the user saw before clicking.
media_typeAd content type: image or video.
video_urlURL of the ad video. Present when media_type is video.
thumbnail_urlURL of the ad content’s thumbnail.
ctwa_clidClick to WhatsApp Click ID: unique identifier for the click, useful for attribution and reporting.
welcome_message.textWelcome message configured in the ad, which starts the conversation.
Available fields depend on the ad. An image ad won’t include video_url, and some fields may arrive empty depending on how the creative is configured.

Using it in your flow

Inside any node you can access the ad data with the memory syntax {{$memory._referral.field}}. For example:
  • {{$memory._referral.source_type}}ad
  • {{$memory._referral.ctwa_clid}} → click identifier for attribution
  • {{$memory._referral.body}} → the ad copy the user saw
A common way to leverage it is to branch the flow based on the source:
1

Check whether the conversation comes from an ad

At the start of the flow, evaluate whether _referral exists in memory. If it does, the conversation arrived from a Click to WhatsApp ad.
2

Save the attribution for reuse

Keep ctwa_clid and source_id in memory or send them to your CRM to attribute the lead to the source campaign.
3

Personalize or route based on the ad

Use body, source_url, or source_id to tailor the agent’s first reply, route to the right team, or trigger an internal notification.
The _referral object is only injected when the conversation originates from the ad. If the user already had a prior conversation with the number and messages again without going through the ad, the referral may not be available.

Memory

How to read and persist variables across conversations and nodes.

Google Ads

Attribute WhatsApp conversations to your Google Ads campaigns.