Skip to content
Dericson Calari
Back to the blog
Capa do artigo: Conversions of WhatsApp with n8n: webhook, ctwa_clid and API the Meta

Conversions of WhatsApp with n8n: webhook, ctwa_clid and API the Meta

Learn how to capture the reference of ads that open the WhatsApp, guard the ctwa_clid at its base and send conversion events to Meta with n8n. See the payload, tests, and limits of the assignment.

Foto de Dericson Calari

Published on10 min read

A campaign that opens conversation in the WhatsApp it doesn’t go through your website. Therefore, the pixel of the site does not see alone what happens after the message. With a API officer of the WhatsApp and the n8n, you can record the origin of the conversation on its basis and inform Meta when a real result occurs, such as a lead qualified or a confirmed purchase. This guide shows the flow, payload, and tests required.

In the video above, I show the logic of capturing the conversation and informing the result to Meta. Here I organize the steps and update a decisive detail: the identifier ctwa_clid comes in the webhook's referral object when the conversation is born from a Click to WhatsApp. It should not be copied to the field fbc.

Why use the N8N to track conversions of the WhatsApp?

The n8n receives the webhook, validates the fields, records the conversation and triggers the sending of events when your system proves a stage of the funnel. First-party data collection is to collect and store this data on its own basis; conversion tracking is to inform the result to the ad platform. The two depend on the quality of the origin and the recorded event.

  • Origin at its base: save ctwa_clid and source_id when they come in the webhook referral and associate them with the conversation.
  • Flow control: the n8n allows you to validate payloads, record history and treat failures and duplications.
  • Cost under control: compare hosting, volume of executions and maintenance before choosing an architecture.
  • Signal for the Meta: report real results and check the receipt; this does not guarantee automatic attribution or improvement.
“Technical reference: Meta documentation for a API from Conversions into commercial messages — developers.facebook.com/docs/marketing-api/conversions-api/business-messaging. Check out the current version before implementing.

Prerequisites before you start

Before diving into the setup, make sure you have the following elements at hand. This preparation is crucial to the success of automation.

Accounts and Access Required

  • **Account no N8N:** You can use the cloud version (n8n.io) or install the self-hosted version. The cloud is simpler to start with.
  • Access to the Meta: have permissions for the WhatsApp Business, for the message data source and to test events in the Event Manager.
  • **Number of WhatsApp Business:** An active number linked to the API Officer of the WhatsApp (via Meta). This tutorial focuses on campaigns that use 'Click to WhatsApp' of the ads, which generate the necessary parameters.
  • Integration Token: Use a token with the permissions required by the configured endpoint and store it in the credentials of the n8n.

Knowledge of the Parameters of First-party data collection

To relate a conversation to an ad Click to WhatsApp, check out the fields that a API official delivery in the referral object of the initial message webhook:

  • ctwa_clid: identifier made available in the webhook referral for conversations initiated by ads Click to WhatsApp. Send it as user_data.ctwa_clid in the message event.
  • source_id: reference of the origin of the ad in the referral, useful for own analysis. It is not a complete campaign tree and does not define, alone, the source of destination data.

These identifiers arrive on webhook metadata when available; do not assume that they are attached to the URL of the WhatsApp. Save the test payload, check out the referral object and associate the ctwa_clid contact and conversation. An organic message may not bring that reference.

Step by Step: Configuring Automation to Receive Messages

The first automation aims to capture every message received in your number of the WhatsApp Business, extract the important parameters and store that information for processing.

1. Creating the Webhook of WhatsApp no N8N

No N8N, create a new workflow. The first node will be a Webhook (Webhook Node). This node will generate a unique URL that you will configure in the API of the WhatsApp to receive notifications of new messages.

  • Add the 'Webhook' node and configure it as 'POST'.
  • Copy the generated URL (e.g.: https://seu_workflow.n8n.cloud/webhook/xyz).
  • In the configuration of the API officer of the WhatsApp, register the callback URL and do the verification required by the Meta. The names of the screens can change.
  • Select the events to be notified, mainly 'messages'.
  • Test the webhook to ensure the connection is active.

2. Extracting the Parameters of the Message

When a message arrives, inspect the actual payload of the webhook before programming the Code node. In the first contact initiated by an ad, search for the referral object of the message and extract ctwa_clid and source_id when present. Validate missing fields and avoid breaking the flow of organic conversations.

In the usual structure of the webhook of API of the WhatsApp, the message stays in body.entry[0].changes[0].value.messages[0]. Check out messages[0].referral in the paidload received; do not confuse referral with context, which has another purpose. The structure may vary depending on the integration, so use a real sample of your environment.

“Without one ctwa_clid valid, do not invent an identifier. Save the conversation on your base and record that the click assignment has not been proven.

3. Storing the Data of the Lead

Store the source and state of the conversation on a basis under your control, such as PostgreSQL. A spreadsheet is for a small test, but requires care with access, retention and volume. For each conversation, keep only what is necessary:

  • Sender's phone number.
  • CTWA Clid.
  • Source ID.
  • Timestamp of the message.
  • Message content (optional).

This record is the beginning of a history of its own. List the ad reference to the conversation and a confirmed result in the CRM; receiving a message, by itself, does not prove purchase or lead qualified.

Step by Step: Automating the Sending of Conversions to Facebook

The second stage informs Meta of a result that occurred in the conversation. Shoot the event when the corresponding step is proven in your CRM or payment system. Choose the message data source configured for the campaign and test the destination in the Event Manager.

4. Preparing the Requisition for the Goal

No n8n, use an HTTP Node Request to send a POST to the API of Conversions of the Goal. Keep the token in the credentials of the n8n, outside the workflow text.

Use the endpoint format documented by Meta: https://graph.facebook.com/v<VERSAO_CURRENT>/<DATASET_ID>/events. Replace the version and ID with the values of your integration; confirm the supported version in the documentation before you configure.

Source_id helps identify the ad that started the conversation, but does not automatically determine the correct data source for the event. Map each number or integration of WhatsApp to the configured data source, check the permissions and test the route before activating the flow.

5. Structuring the Event Body (Payload)

In the example of the Meta for ad measurement Click to WhatsApp, the central fields are:

  • event_name: use the name of the really proven step, such as Lead or Purchase.
  • event_time: Unix time of the result, not simply from the first message.
  • action_source: business_messaging.
  • messaging_channel: whatsapp; in user_data, include ctwa_clid when the reference is available. The official example also features page_id.
  • custom_data: for Purchase, include value and currency consistent with confirmed purchase.
  • Data source: Send to the message dataset configured for this integration. Do not invent event_source_url for a conversation.
  • event_id: Stable result identifier to recognize retries and avoid duplicate shipping.

In the user_data object, please report ctwa_clid in the field itself. Do not convert it into fbc: are different identifiers. The Meta example also includes page_id. Use additional data only when the modality documentation and its legal basis allow.

“Submitting an event with the correct format confirms only the technical receipt. Attribution and optimization also depend on the data source, click reference, event quality and platform rules.

6. Encrypting the Data and Sending

Validate the event in the Meta test environment and record the response of the API. Treat failures, repeated attempts and duplications with a event_id stable for the same result. Do not send a Purchase until payment is confirmed.

Creating one CRM Basic and Dashboard no N8N

Take advantage of the structure you have already set up to go beyond the first-party data collection. With the data stored, you can create automatic rankings for the leads (e.g. ‘Interested’, ‘Potential Customer’) based on message content or conversation flow. Use us as 'IF' or 'Switch' to label them.

In addition, the N8N allows you to integrate with data visualization tools or even export to Google Data Studio. You can create a simple panel that shows:

  • Leads received per day.
  • Results confirmed by origin, when the webhook brought source_id and the CRM recorded the stage.
  • Cost per lead (integrating with spending data from the API from Facebook).
  • Funnel steps (message received, response sent, qualified conversion).

Final Tips to Optimize Your Campaigns

  • Test the source: Click on a test ad and check out the webhook referral and link to the conversation.
  • Test the event: use the Meta testing tool and check out payload, response of the API and data source.
  • Monitor quality: compare events sent with confirmed results in the CRM and investigate disagreements.
  • Protect tokens and personal data: use credentials of the n8n, control access and define retention.

Frequently Asked Questions (FAQ)

1. Do I need to have a server of my own to use the N8N?

Not necessarily. You can start with the cloud version hosted on the n8n.io, which is sufficient for most cases. For greater control and very high volume, self-hosted installation is an option.

2. Does Facebook accept the phone number in place of email for sending conversions?

It depends on the mode of event. In the official ad measurement example Click to WhatsApp, the main identifier is user_data.ctwa_clid, along with the other fields required by integration. Don't change ctwa_clid by phone do not treat a phone hash as guarantee of assignment.

3. What if the user deletes the initial message or the parameter is lost?

If the first webhook does not bring referral or ctwa_clid, record the absence. Do not fill in the identifier manually or assume that a later message will retrieve the source; investigate the configuration of the API and take a test with a real announcement.

4. Can I use this method to track purchase conversions (Purchase) in the WhatsApp?

Yes, if the purchase was indeed confirmed in your system. Send Purchase with result event_time, consistent value and currency and a event_id stable. Message received or purchase intention should not become Purchase.

5. How long does it take for the conversion to appear in the Ads Manager?

Use the Event Manager and the response of the API to check the receipt. Processing time and display in reports may vary; accepted event does not mean conversion assigned to the ad.

6. Is it possible to do this with tools like Zapier or Make?

The logic can be implemented in other tools that receive webhook, save the reference of the conversation and make the request to the Meta. Compare support for payloads, testing, security and actual costs before choosing.

7. How do I deal with several numbers of WhatsApp or multiple ad accounts?

Map each number and integration to the correct data source. For multiple numbers or accounts, a configuration table in the n8n or at its base is more secure than deducing the destination by the source_id of the ad. Test each combination.

8. This method violates the terms of service of the WhatsApp or Facebook?

Use a API official, respect the current permissions and policies of the Meta and process the personal data in accordance with the applicable legislation. The technical configuration alone does not prove compliance; review the purpose, access and retention of records.

The path is simple to understand, but it needs validation: capture the ad reference on the webhook, save the origin at its base, record the actual result and send the event to the correct data source. Test each step separately and compare the events received with the results of the CRM.