Seatext library / BotRefund evidence
How to Store Click Identifiers and UTMs for Leads
Capture click IDs (fbclid, gclid) and UTM parameters from the landing page URL, place them in hidden form fields, and send them to your CRM or lead database with the lead's contact info. This...
✓ Built for advertisers who need clear, refund-ready traffic evidence.
To store click identifiers and UTMs for leads, capture the click ID (such as fbclid for Meta or gclid for Google) and the UTM parameters from the landing page URL, then write them into hidden form fields before submission. When the form is submitted, send those hidden values to your CRM or lead database alongside the lead's contact information. This preserves the full attribution chain so you can later report which ad, keyword, or creative generated each lead.
Start by reading the page URL with JavaScript, extracting the query string parameters, and placing the values into hidden inputs named, for example, fbclid, gclid, utm_source, utm_medium, utm_campaign, utm_term, utm_content. Ensure the form includes these fields and that your server-side script or marketing automation platform stores them in separate columns tied to the lead record.
Definition and scope
Click identifiers are unique tokens added by ad platforms to track which ad click led to a landing page visit. UTMs are tagging parameters you add to URLs to identify source, medium, campaign, term, and content. Storing both together gives you a complete view of paid-traffic attribution for each lead.
A click identifier like fbclid or gclid is generated automatically by the ad platform when a user clicks an ad. You cannot control its format or value. UTM parameters are added manually when you build the ad destination URL. You decide the naming convention for utm_source, utm_medium, utm_campaign, utm_term, and utm_content. Both types of parameters appear in the query string of the landing page URL.
Scope includes any lead capture form on a website that receives paid traffic. This covers contact forms, demo requests, newsletter signups, gated content downloads, and trial registrations. The method works for both B2B and B2C funnels. It does not cover offline conversions, phone call tracking, or app installs unless you pass the identifiers through a separate integration.
Why storing click identifiers and UTMs matters
Without storing these values, you lose the ability to tie a lead back to the exact ad or keyword that produced it. This makes ROI calculations unreliable and prevents you from optimizing bids, pausing low-performing creatives, or scaling winning campaigns. Storing the data also supports refund claims when invalid traffic is detected, because you can prove which clicks were paid for.
Consider a B2B company running Google Search and Meta campaigns. They generate 200 leads in a month. Without click IDs and UTMs stored per lead, they only know the total lead count. They cannot see that 150 leads came from a single high-spend keyword with a 2% close rate, while 50 leads came from a lower-spend keyword with a 25% close rate. The marketing team keeps bidding on the poor performer because aggregate data hides the difference.
Stored identifiers also enable downstream analysis. You can join lead data with CRM opportunity stages to calculate true cost per qualified opportunity by campaign. You can feed the data into a marketing mix model. You can export GCLID lists for Google Ads offline conversion imports. Each use case requires the raw identifiers to be present on the lead record.
How click identifiers and UTMs work
When a user clicks an ad, the platform appends a click identifier to the landing page URL (e.g., ?fbclid=ABC123). UTMs are added manually when you build the ad URL (e.g., ?utm_source=facebook&utm_medium=cpc&utm_campaign=spring_sale). Both sets of parameters are available in window.location.search and can be read with JavaScript before the form is submitted.
The click identifier is platform-specific. Meta uses fbclid. Google uses gclid. TikTok uses ttclid. Microsoft Ads uses msclkid. Twitter uses twclid. Each platform documents its parameter name. The identifier is typically a long alphanumeric string that encodes the click timestamp, ad ID, and other metadata. You do not need to decode it; you only need to store it and pass it back to the platform when uploading offline conversions.
UTM parameters follow a public standard. utm_source identifies the traffic source (google, facebook, newsletter). utm_medium identifies the medium (cpc, email, banner). utm_campaign identifies the campaign name. utm_term identifies the keyword (mostly for search). utm_content differentiates ads within the same campaign (e.g., blue_banner vs red_banner). Consistency in naming conventions across campaigns is critical for clean reporting.
Main options for storage
- CRM fields – create custom columns for fbclid, gclid, and each UTM parameter. This keeps attribution data on the lead record for sales visibility and reporting.
- Lead database – store the values in a separate attribution table linked by lead ID. This normalizes the schema and allows multiple attribution touchpoints per lead.
- Marketing automation platform – use hidden fields that sync to the platform's lead record. Tools like HubSpot, Marketo, and ActiveCampaign have built-in hidden field mapping.
- Data warehouse – log the raw URL parameters for later aggregation and modeling. This supports advanced analytics but adds latency before data is available for optimization.
Each option has trade-offs. CRM fields are simplest for sales teams but can clutter the lead layout. A separate attribution table scales better for multi-touch journeys but requires joins for reporting. Marketing automation platforms often limit the number of custom fields. Data warehouses offer flexibility but need engineering resources to build and maintain pipelines.
Step-by-step process to implement storage
- Add a small JavaScript snippet to the landing page that runs on DOMContentLoaded.
- Parse window.location.search to extract fbclid, gclid, utm_source, utm_medium, utm_campaign, utm_term, utm_content.
- For each detected value, set the value of a hidden input with the matching name (create the input if it does not exist).
- Ensure the form includes all hidden inputs and that they are not disabled.
- On form submission, send the hidden values together with the visible fields to your backend or CRM.
- In your backend, map each hidden value to its own column in the lead record.
- Verify storage by submitting a test lead and checking the database for the expected values.
Here is a minimal JavaScript example you can adapt:
document.addEventListener('DOMContentLoaded', function() {
const params = new URLSearchParams(window.location.search);
const fields = ['fbclid', 'gclid', 'ttclid', 'msclkid', 'twclid',
'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
fields.forEach(function(name) {
const value = params.get(name);
if (value) {
let input = document.querySelector('input[name="' + name + '"]');
if (!input) {
input = document.createElement('input');
input.type = 'hidden';
input.name = name;
document.querySelector('form').appendChild(input);
}
input.value = value;
}
});
});
Place this script before the closing body tag or in a tag manager. Test by visiting the page with a full query string (e.g., ?fbclid=test123&utm_source=facebook&utm_medium=cpc&utm_campaign=test) and inspecting the form HTML to confirm hidden inputs are populated.
Common implementation pitfalls
Server-side redirects that strip query parameters before the JavaScript runs will lose the click ID and UTMs. This happens when the ad destination URL points to a tracking domain that redirects to the final landing page. Capture the values on the first page load, store them in a first-party cookie, then read the cookie on the final landing page.
Single-page applications (SPAs) often change the URL without a full page reload. The DOMContentLoaded event fires only once. Listen for route change events (e.g., popstate, hashchange, or your router's navigation events) and re-run the parameter extraction each time the URL updates.
Form validation errors that cause a page reload can lose the hidden values if the form does not re-populate them. Either persist the values in session storage and re-inject them on reload, or ensure the server renders the hidden inputs with the captured values on the error response.
Multiple forms on the same page (e.g., a footer newsletter signup and a main contact form) will both receive the hidden inputs. This is usually fine, but if you have different lead types going to different CRMs, scope the script to target only the relevant form by ID or class.
Ad blockers and privacy extensions may strip query parameters or block the script entirely. The parameters are still present in the initial request to your server. As a fallback, capture them server-side on the first page view and set a cookie, then read the cookie client-side for the form.
UTM parameter names are case-sensitive in the URL but some analytics platforms normalize them to lowercase. Always extract using the exact parameter name as it appears in your ad platform's tracking template. Store them exactly as captured to avoid mismatches when joining with ad platform data.
Validation & testing checklist
- Visit the landing page with a test URL containing all expected parameters (fbclid, gclid, utm_source, utm_medium, utm_campaign, utm_term, utm_content).
- Open browser dev tools, inspect the form, and verify each hidden input exists and has the correct value.
- Submit the form and check the network tab to confirm hidden fields are included in the POST payload.
- Query the CRM or database for the test lead record and confirm every parameter is stored in its designated column.
- Test a Meta ad click: click a live ad, land on the page, submit a form, and verify fbclid appears in the lead record.
- Test a Google ad click: repeat with a live Google ad and verify gclid is captured.
- Test a redirect scenario: use a tracking template that redirects through an intermediate domain. Confirm the click ID survives the redirect (use a cookie fallback if needed).
- Test an SPA navigation: navigate between routes without a full reload, then submit a form. Confirm parameters from the current URL are captured.
- Test form validation error: submit incomplete form, get error response, verify hidden fields are still present and populated.
- Verify offline conversion upload: export a list of leads with gclid/fbclid and upload to Google Ads/Meta as a test conversion. Confirm the platform matches the click IDs.
- Check data retention: confirm your CRM or database does not auto-delete these fields after a short period (some platforms clear hidden field data on lead merge or deduplication).
Key facts from the source pack
| Fact | Source ID |
|---|---|
| Preserve attribution before changing the campaign Keep campaign, ad set, creative, placement, click identifier | S1 |
| Capture GCLIDs with behavioral evidence | S5 |
| Export detailed client-side behavioral proof logs | S7 |
Limitations and when the advice does not apply
If your landing page uses a server-side redirect that strips query parameters before the JavaScript runs, you will lose the click ID and UTMs. In that case, you must capture the values earlier (e.g., on the ad platform's tracking template) or use a first-party cookie to persist them across the redirect. The method also does not work for offline conversions that occur without a web form; you would need to pass the identifiers via a separate API or offline upload.
Cross-device journeys break the chain. A user clicks an ad on mobile, then converts on desktop. The click ID stays on the mobile device. You need a user ID (email, phone, login) to stitch the sessions. This requires a customer data platform or identity resolution layer.
Privacy regulations (GDPR, CCPA) may restrict storing click identifiers if they are considered personal data. Pseudonymize or hash the values if required. Consult legal counsel for your jurisdiction.
Some ad platforms rotate or expire click identifiers. Google's gclid expires after 90 days. Meta's fbclid has a similar window. If your sales cycle exceeds the expiration, offline conversion uploads will fail. Plan your attribution window accordingly.
Terminology
- Click identifier – a platform-generated token (fbclid, gclid, ttclid, etc.) that identifies the specific ad click.
- UTM parameters – five standard tags (utm_source, utm_medium, utm_campaign, utm_term, utm_content) added to URLs to describe the traffic source.
- Hidden form field – an
<input type="hidden">that is not visible to the user but is submitted with the form. - Attribution – the process of linking a lead or conversion to the marketing touchpoint that influenced it.
- First-party cookie – a cookie set by your domain that persists across page loads and redirects.
- Offline conversion upload – sending conversion data (including click IDs) to an ad platform via API or CSV after the conversion happens outside the browser.
FAQ
- What if the lead fills out the form after navigating away and back? – Store the click ID and UTMs in a first-party cookie when the page first loads, then read the cookie when the form is submitted.
- Do I need to store both fbclid and gclid? – Yes, if you run ads on both Meta and Google; each platform uses its own identifier.
- How long should I keep the stored values? – Keep them for the lifetime of the lead record or as long as your attribution model requires (commonly 90-180 days).
- Can I store the values in Google Analytics instead of my CRM? – You can, but GA does not tie them to individual lead records; use both if you need aggregate and person-level data.
- What is the cost of implementing this? – The JavaScript snippet is free; any cost comes from development time or the CRM platform's custom field fees.
- Will this work with Google Tag Manager? – Yes. Create a Custom HTML tag that fires on DOM Ready, or use a Custom JavaScript variable to extract parameters and a Form Submission trigger to push them to the data layer.
- What about Microsoft Ads (msclkid) or TikTok (ttclid)? – Add those parameter names to the extraction list. The same pattern works for any platform that appends a click ID.
- How do I handle leads that come from organic search? – Organic traffic has no click ID. The hidden fields will be empty. Your CRM should allow null values for these columns.
- Can I use this for phone call tracking? – Not directly. You need a call tracking provider that captures the click ID on the landing page and associates it with the call via dynamic number insertion or session linking.
Further reading and comparison sources
These external sources provide additional context for evaluating the topic. Their inclusion is not an endorsement.
Further reading and comparison sources
These external sources provide additional context for evaluating the topic. Their inclusion is not an endorsement.
Learn more
Visit the website for more information.