Widget attribution tracking and the manual attribution API
Widget attribution tracking and the manual attribution API
Capture UTM and ad click data automatically from your LeadTruffle widgets, or push values manually with setAttribution for advanced installs.
LeadTruffle's JavaScript widgets automatically capture marketing attribution and page context whenever a visitor submits a lead — UTM parameters, ad click IDs, page URL, referrer, and more. Most businesses don't need to set anything up. This guide explains what gets captured, how it works, where to find it, and how agencies or developers can push attribution manually when needed.
Table of contents
- Overview
- What gets captured
- How automatic attribution works
- Google Ads cookie fallback
- Pushing attribution manually
- Supported widgets and fields
- Where attribution shows up in LeadTruffle
- Sending attribution to webhooks and Zapier
- Troubleshooting
Overview
Every time a visitor submits a lead through a LeadTruffle JavaScript widget, the widget records where that lead came from — the ad campaign, the search click, the page they were on, and more. This is called attribution.
You can use attribution to see which ads and campaigns are actually producing leads, send that data into your CRM, and report on revenue by source.
What gets captured
When a lead is submitted, the widget collects whatever tracking values are available, including:
- Campaign details — UTM source, medium, campaign, term, and content
- Ad click IDs — Google, Meta, Microsoft, TikTok, Snapchat, and more
- Page context — page URL, page title, and referrer
- Analytics IDs — Google Analytics client/session IDs and the HubSpot user token when present
If none of these values are available for a lead, the attribution section simply won't appear on that lead — lead capture is never blocked.
How automatic attribution works
The widget uses first-touch attribution. It remembers where a visitor originally came from, even if they browse to other pages before submitting.
When the widget loads, it:
- Checks the browser for a recently saved attribution record.
- If a fresh record exists, it keeps it — this preserves the original first touch.
- If no record exists, it reads tracking values from the current page URL.
- If a Google
gclidisn't in the URL, it tries the Google Ads cookie as a fallback. - If it finds any tracking values, it saves them in the browser.
Saved first-touch attribution lasts 7 days.
When the visitor submits, the widget builds the final attribution in this priority order:
- Current page URL values win first.
- Missing fields are filled from the saved first-touch record.
- A missing
gclidis filled from the Google Ads cookie. - Remaining gaps can be filled from a same-domain referrer URL.
This means a visitor can land on a tagged ad URL, browse to another page, submit from there, and the lead still includes the original campaign data — as long as the widget loaded on that first page and the browser allowed storage.
Google Ads cookie fallback
Google Ads can store click data in a first-party cookie called _gcl_aw. If a visitor's gclid is no longer in the page URL, the widget can read this cookie as a backup so the Google click ID still makes it onto the lead.
A few things to know:
- A
gclidin the page URL always wins over the cookie. - A saved first-touch
gclidalso wins over the cookie. - The cookie only recovers
gclid— it does not contain UTM fields. - If the cookie is missing, blocked by a consent tool, or unreadable, the widget just continues without it.
Pushing attribution manually
For advanced installs, you can push attribution values directly into the widget using setAttribution(...). This is useful when your site, tag manager, consent manager, or analytics script already has the values and needs to hand them to LeadTruffle before the visitor submits.
Call setAttribution(...) after the widget script loads and before the visitor submits the form. Here's the recommended pattern for the Website Texting / Chat Widget:
const script = document.createElement('script')
script.src = 'https://embeds-v1.leadtruffle.com/widget/tooldesk-widget.js'
script.onload = function () {
window.LTWidget.initialize({
companyId: 'YOUR_COMPANY_UUID',
})
if (window.LTWidget && typeof window.LTWidget.setAttribution === 'function') {
window.LTWidget.setAttribution({
gclid: 'GOOGLE_CLICK_ID',
utm_source: 'google',
utm_medium: 'cpc',
utm_campaign: 'spring-service',
})
}
}
document.head.appendChild(script)
A few important behaviors:
- It merges, it doesn't replace. Manual values are added to whatever attribution was already captured. Sending only
gclidwon't wipe out an existingutm_source. - Manual values can overwrite the same field. If saved attribution has one
gclidand you push a new one, the new value is kept. - The current page URL still wins at submit time. If the submission URL contains a
gclid, that value takes priority over a manually pushed one. - Bad input is ignored safely. Empty strings, non-text values, and unknown fields are dropped — a bad call won't break your page or the lead form.
prefillLead(...) for attribution. That method is for visible lead fields and custom metadata like name, email, or phone. Always use setAttribution(...) for gclid, UTMs, and other click IDs.Supported widgets and fields
Manual attribution works on every current LeadTruffle JavaScript widget. Replace LTWidget in the example above with the global for your widget:
Widget | Global |
|---|---|
Website Texting / Chat Widget | |
Webchat Widget | |
Pop-Up Widget | |
JavaScript Lead Form | |
Franchise Widget | |
setAttribution(...) accepts any of these fields — send only the ones you have:
Field | What it tracks |
|---|---|
| Campaign details |
| Google Ads |
| Meta (Facebook / Instagram) |
| Microsoft Ads |
| TikTok Ads |
| Snapchat Ads |
| |
| Google Search / Shopping |
Where attribution shows up in LeadTruffle
Lead details
Open any lead on the Leads tab and expand Attribution & Tracking. You'll see campaign details, ad platform tracking, other tracking IDs, and page context. If no attribution was captured, this section won't appear for that lead.
Inbox and conversation details
The inbox uses attribution signals to label a lead's source — for example, a lead with a Google click ID can be shown as a Google lead and grouped accordingly.
Dashboard lead sources
Your lead source analytics turn stored attribution into readable source labels, such as:
- Google Ads (from
gclid,gbraid,wbraid, orgad_source) - Meta Ads (from
fbclid) - TikTok Ads (from
ttclid) - Microsoft Ads (from
msclkid) - Snapchat Ads (from
snapcid) - Campaign labels from UTM fields, and referrer labels like Google Search, YouTube, Yelp, Thumbtack, or Angi
CSV exports
Lead exports include attribution columns such as Referrer, Submission URL, all UTM fields, GCLID, GBRAID, WBRAID, Google Ads source, IGSHID, GCLSRC, SRSLTID, and GA Client ID.
Sending attribution to webhooks and Zapier
For outgoing webhooks and Zapier, LeadTruffle maps stored attribution into a trackingData object. You can map fields like trackingData.gclid, trackingData.utm_source, and the rest into HubSpot, Google Sheets, your CRM, or an offline conversion step.
{
"trackingData": {
"source": "chat-widget",
"utm_source": "google",
"utm_medium": "cpc",
"utm_campaign": "spring-service",
"gclid": "Cj0KCQ...",
"ga_client_id": "123456789.987654321",
"pageInfo": {
"currentUrl": "https://example.com/services/plumbing",
"referrer": "https://www.google.com/",
"title": "Plumbing Services"
}
}
}Troubleshooting
gclid is still empty in Zapier or HubSpot
Check each of the following:
- Was the visitor's landing page URL tagged with
gclid,gbraid, orwbraid? - Did the LeadTruffle widget load on that landing page?
- Did the visitor submit within the 7-day saved attribution window?
- Does the visitor's browser allow local storage for your site?
- Is the
_gcl_awcookie present and readable on the submission page? - Is a consent manager blocking ad cookies or widget storage until after submission?
- Is your site running the current widget version?
- If pushing values manually, is
setAttribution(...)called after the widget loads and before submission?
UTM fields are missing but gclid is present
The Google Ads cookie can recover gclid, but it never contains UTM fields. To keep UTMs after page navigation, load the widget on the first tagged landing page or push the UTM values with setAttribution(...).
You want to push values before the widget loads
The widget global must exist before it can receive attribution. Store the values in your own variable, cookie, or data layer first, then call setAttribution(...) from the script's onload handler.
You're using the iframe form
The legacy iframe form doesn't support attribution tracking or manual injection. Switch to the JavaScript Lead Form widget.
trackingData.Need help? Contact us at support@leadtruffle.com or message the team via the chat on this article or in-app.
Updated on: 09/06/2026
Thank you!