Skip to main content

UC-007 — Templates with Tracked Links

Goal
Create WhatsApp templates with tracked buttons, so that the platform records the clicks
Channel
WhatsApp
Estimated time
30 minutes

Real-world scenarios​

  • ShopItalia — Measure CTR: Track how many users click the "Go to shop" button in the promotional template, and read the clicks and the click rate in the campaign report of the Qlara web app.
  • TravelDream — Landing page tracking: Each recipient receives a unique link to the travel offer landing page, with UTM parameters for Google Analytics analysis.
  • MarketingPro — A/B testing links: Send two template variants with different links (landing A vs landing B), each in its own campaign, and compare their clicks in the campaign report of the Qlara web app.

The diagram shows the complete cycle: template creation with tracking, the campaign that sends it to the recipients, and the click, recorded on the platform before the recipient is taken to the landing page. No click event is sent to your server.

Prerequisites​

  • Active API Key with WhatsApp template and campaign permissions
  • Verified WhatsApp Business number (see UC-005)
  • Contact list created and populated (see UC-011)
  • HTTPS landing page ready for tracking
  • Familiarity with WhatsApp templates (see UC-006)

Create a WhatsApp template with trackButtonLinks: true to enable automatic click tracking. The phoneNumberId query parameter associates it with your WhatsApp Business number, and the button keeps your landing page URL, UTM parameters included:

curl -X POST "https://api.qlara.ai/api/message-server/whatsapp/templates?phoneNumberId=5" \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "promo_estate_tracked_2026",
"lang": "it",
"category": "MARKETING",
"headerFormat": "IMAGE",
"headerMediaUrl": "https://cdn.shopitalia.it/promo/estate-2026-header.jpg",
"body": "Ciao {firstName}, i saldi estivi sono arrivati! Sconto del 50% su tutta la collezione fino al 30 giugno.",
"buttons": [
{
"type": "URL",
"text": "Vai allo shop",
"url": "https://shopitalia.it/promo/estate2026?utm_source=whatsapp&utm_campaign=promo_estate"
}
],
"trackButtonLinks": true
}'

Placeholders must be contact fields of your account, such as {firstName}: fixed values like the discount and the end date go straight into the text.

Response — Template submitted​

The API answers 201 Created with the template in PENDING status. Below are its main fields: in buttons the URL is now the tracking link registered with Meta, while your URL stays in originalButtonUrls.

{
"id": 187,
"phoneNumberId": 5,
"name": "promo_estate_tracked_2026",
"slug": "promo_estate_tracked_2026",
"category": "MARKETING",
"lang": "it",
"status": "PENDING",
"createdAt": "2026-04-09 10:00:00.000+0000",
"updatedAt": "2026-04-09 10:00:00.000+0000",
"headerFormat": "IMAGE",
"body": "Ciao {firstName}, i saldi estivi sono arrivati! Sconto del 50% su tutta la collezione fino al 30 giugno.",
"originalButtonUrls": [
{
"index": 0,
"url": "https://shopitalia.it/promo/estate2026?utm_source=whatsapp&utm_campaign=promo_estate"
}
],
"placeholders": ["firstName"]
}
Meta approval

The template must be approved by Meta before use. The process typically takes from a few minutes to 24 hours. Monitor the status with a GET on the template.

Behind the scenes — How link tracking works
  1. URL rewriting: When trackButtonLinks: true is active, the gateway registers the button with Meta under an intermediate tracking URL and keeps the original URL in originalButtonUrls. Each message sent then gets its own short code in that URL.
  2. Click capture: When the recipient clicks the button, the tracking service records the time of the click and the short link it came through, and so the message it was sent in, plus the visitor's device, browser, operating system, country and referrer. Bot clicks are flagged and left out of the counts. The template is not recorded.
  3. Redirect: After recording the click, the tracking service takes the visitor to the original URL. On plans that include the link shortener this is an immediate HTTP 303 redirect. On the other plans, and whenever the plan cannot be checked, it is an intermediate page with your account's logo and name that continues to the original URL after about 3 seconds.
  4. UTM parameters: UTM parameters in the original URL are preserved in the redirect, allowing attribution in Google Analytics or other analytics tools.
  5. Where to read the clicks: The campaign report of the Qlara web app shows the clicks (bots excluded), the click rate on delivered messages and the clicks per button. No API endpoint, export or webhook returns click data, and there are no unique-click, time-to-click or hourly figures.
  6. Link lifetime: A tracked link stays active for 365 days on plans that include the link shortener and for 30 days on the others. A change of plan moves the expiry: an upgrade extends the links to 365 days from the change, a downgrade cuts longer-lived ones to 90 days. An expired link answers 404.

Step 2 — Send the template with a campaign​

Once the template is approved, create a campaign that sends it to a contact list. Pass the number and the template in the same request, as whatsappPhoneNumberId and whatsappTemplateId: the tracked button needs nothing more, and the header image saved with the template is used too. {firstName} is filled in for each recipient from the contact.

curl -X POST https://api.qlara.ai/api/partner-gateway/campaigns \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "Promo estate tracciata",
"sendingMode": "WHATSAPP",
"destinationType": 0,
"whatsappPhoneNumberId": 5,
"whatsappTemplateId": 187,
"contactListIds": [415],
"readyToSend": true
}'

Response — Campaign ready to confirm​

The API answers 201 Created with the campaign, ready to be confirmed ("readyToSend": true). Nothing is sent yet. Check the price as shown in UC-008, then confirm with the id of the campaign (3912 here):

# 202 Accepted, no body: the campaign starts sending
curl -X PUT https://api.qlara.ai/api/partner-gateway/campaigns/3912/confirm \
-H "X-Api-Key: YOUR_API_KEY"
No links in the campaign

The campaign does not list the tracking links: each message gets its own short link to the URL of originalButtonUrls when it is sent.

Expected result​

StepActionResult
1POST /whatsapp/templatesTemplate created with trackButtonLinks: true
2Meta approvalStatus APPROVED
3POST /campaigns + PUT /confirmCampaign confirmed: messages sent with tracked links
4Recipient clickClick recorded on the platform + redirect to the landing page

Complete end-to-end example​

# 1. Create template with tracking (one-time, wait for approval)
curl -s -X POST "https://api.qlara.ai/api/message-server/whatsapp/templates?phoneNumberId=5" \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "promo_estate_tracked_2026",
"lang": "it",
"category": "MARKETING",
"body": "Ciao {firstName}, sconto del 50% fino al 30 giugno!",
"buttons": [
{"type": "URL", "text": "Vai allo shop", "url": "https://shopitalia.it/promo?c=estate2026"}
],
"trackButtonLinks": true
}' | jq .

# 2. After approval, create the campaign, ready to confirm (187 is the id returned in step 1)
CAMP_ID=$(curl -s -X POST https://api.qlara.ai/api/partner-gateway/campaigns \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "Promo estate tracciata",
"sendingMode": "WHATSAPP",
"destinationType": 0,
"whatsappPhoneNumberId": 5,
"whatsappTemplateId": 187,
"contactListIds": [415],
"readyToSend": true
}' | jq -r '.id')

echo "Campaign ID: $CAMP_ID"

# 3. Check the price and the number of recipients
curl -s "https://api.qlara.ai/api/partner-gateway/campaigns/${CAMP_ID}/price" \
-H "X-Api-Key: YOUR_API_KEY" | jq '{totalPrice, walletKind, numOfDistinctContact}'

# 4. Confirm: the messages go out with the tracked button
curl -s -X PUT "https://api.qlara.ai/api/partner-gateway/campaigns/${CAMP_ID}/confirm" \
-H "X-Api-Key: YOUR_API_KEY"

Variants​

Template with multiple tracked buttons​

Track clicks on multiple buttons: the campaign report of the Qlara web app breaks the clicks down per button, so give each button a distinct URL to see which CTA works better:

curl -X POST "https://api.qlara.ai/api/message-server/whatsapp/templates?phoneNumberId=5" \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "multi_cta_tracked_2026",
"lang": "it",
"category": "MARKETING",
"body": "Ciao {firstName}, scopri le nostre offerte!",
"buttons": [
{"type": "URL", "text": "Offerte donna", "url": "https://shop.it/donna?c=spring"},
{"type": "URL", "text": "Offerte uomo", "url": "https://shop.it/uomo?c=spring"}
],
"trackButtonLinks": true
}'

Every URL button is tracked on its own: originalButtonUrls lists the original URLs, with index 0 and 1. Plan the URLs before creating the template: a later update cannot change the destinations of tracked buttons (see Update template).

Common errors​

400 Bad Request — Placeholder not allowed​

{
"status": "fail",
"data": {
"message": "INVALID_PLACEHOLDER",
"errors": ["percentualesconto"]
}
}

Solution: Placeholders must be contact fields of your account (such as {firstName} or {city}) or {shortLinkT1}–{shortLinkT4}. Write fixed values, such as the discount, straight into the text.

400 Bad Request — Invalid button URL​

{
"status": "fail",
"data": {
"message": "INVALID_BUTTON_URL",
"errors": ["The URL in the button is not valid."]
}
}

Solution: Meta rejected the URL of a button. Use a complete, valid URL, such as https://shopitalia.it/promo.

Errors of the campaign calls​

POST /campaigns and PUT /campaigns/{id}/confirm answer with generic messages that do not name the field that failed: see the common errors of UC-008.

401 Unauthorized — Missing or invalid API Key​

The template endpoint answers 401 with an empty body, the campaign endpoints with {"error": "Invalid API Key"}.

Solution: Verify that the X-Api-Key header is present and that the key is active in the platform dashboard.

Next steps​

References​