Skip to content

Page Context and Attribution

Mcdavid Obioha edited this page Dec 2, 2026 · 1 revision

Page Context and Attribution

Know which page, and which campaign, a WhatsApp lead came from. When enabled, the widget appends a short footer to the message.

<WhatsAppChat phoneNumber="+12025550123" includePageContext />

The message the visitor sees in WhatsApp:

Name: Ada
Subject: Quote

Hi, I'd like a quote for 20 seats.

---
Page: Pricing | Acme
URL: https://acme.com/pricing
Source: newsletter / spring-sale
UTM: medium=email, term=crm, content=hero

Options

Pass true for the defaults, or an object:

Option Meaning Default
includeTitle The page title (document.title). true
includeUrl The page URL: origin and path only. true
includeUtm utm_source, utm_medium, utm_campaign, utm_term, utm_content from the current query string. true
includeReferrer The referring page (origin and path only). false
label Label for the title line. Page
<WhatsAppChat
  phoneNumber="+12025550123"
  includePageContext={{ includeReferrer: true, includeUtm: true, label: 'Viewing' }}
/>

Privacy and safety

  • The URL never includes the query string or the hash, because those often contain tokens, emails or session ids. Only the five utm_* values are read from the query string.
  • The referrer is off by default and is also reduced to origin and path.
  • Every value has control characters and line breaks removed and is length-limited, so a crafted link cannot inject extra lines into the message.
  • Page context is read when the visitor presses "Open in WhatsApp", so it reflects the page they are on at that moment, including after client-side navigation.
  • Tell visitors if you collect attribution, as your privacy rules require.

Using it in a custom message

When includePageContext is on, details.page is available in messageTemplate and onSend:

<WhatsAppChat
  phoneNumber="+12025550123"
  includePageContext
  messageTemplate={({ name, message, page }) =>
    `${message}\n\n(${name}${page?.utm.utm_source ? `, via ${page.utm.utm_source}` : ''})`
  }
  onSend={({ page }) => track('whatsapp_lead', { url: page?.url, source: page?.utm.utm_source })}
/>

details.page has title, url, utm (an object with the utm_* keys that were present), referrer, and text (the formatted footer). The default message template appends page.text; a custom messageTemplate decides for itself whether to include it.

Tracking links

Tag your links as usual so there is something to read:

https://acme.com/pricing?utm_source=newsletter&utm_medium=email&utm_campaign=spring-sale

Clone this wiki locally