Sub topic 12
Ad platform pixels and click IDs
This chapter assumes you have GA4 installed, can read UTM-tagged URLs, and know what the data layer and a tag manager do. It covers how ad platforms run their own measurement alongside GA4, and why the two sets of numbers differ.
Why ad platforms need their own tracking
GA4 tells you what happened on your site. An ad platform such as Meta, TikTok, LinkedIn, Pinterest, or X also needs to know which of its ad impressions and clicks led to a conversion. It uses that signal for two jobs:
- Reporting: showing the advertiser conversions next to spend in its own dashboard.
- Optimization: training its delivery system to find more people likely to convert.
GA4 cannot supply this signal. GA4 knows a visit came from utm_source=instagram, but it does not know which ad impression or which user profile on Instagram produced the click. The platform does know that. To link the two, you place the platform's code on your site and pass an identifier from the ad click to your conversion.
The pieces
Pixel (browser tag)
A pixel is a small JavaScript snippet from an ad platform. Meta calls its version the Meta Pixel, TikTok calls it the TikTok Pixel, and LinkedIn calls it the Insight Tag. The pixel does three things:
- It loads the platform's library on your page.
- It reads or sets first-party cookies and reads any click ID in the URL.
- It sends events such as page views, purchases, and leads back to the platform's servers.
The name comes from the old 1x1 transparent image used for tracking. Modern pixels are scripts that also send data with image or fetch requests.
Click ID
A click ID is a unique token that the platform appends to your landing page URL when someone clicks an ad. It identifies that one click.
| Platform | Click ID parameter | Typical first-party cookie |
|---|---|---|
| Meta (Facebook, Instagram) | `fbclid` | `_fbc` (derived from the click ID), `_fbp` (browser ID) |
| TikTok | `ttclid` | `ttclid` stored by the pixel, `_ttp` |
| `li_fat_id` (with first-party cookies enabled) | `li_fat_id` | |
| `epik` | `_epik` | |
| Google Ads | `gclid` | `_gcl_aw` |
Parameter and cookie names change over time, so check each platform's current documentation before you build anything that depends on them.
A landing URL for a Meta ad might look like this:
https://example.com/spring-sale?utm_source=instagram&utm_medium=paid_social&utm_campaign=spring_sale_2026&utm_content=carousel_a&fbclid=IwAR0exampleThe utm_* values are yours. The fbclid value is added by Meta, usually through auto-tagging or a setting on the ad. You do not write it, and you should not remove it.
Conversion event
A conversion event is the message the pixel sends when a visitor completes something that matters, such as a purchase or a lead. Each platform has standard event names, for example Lead, CompleteRegistration, and Purchase on Meta. Using the standard names lets the platform optimize for them.
How the pieces connect
Two separate systems receive the same visit. Each applies its own rules for who gets credit. That is the main reason their numbers differ, which the later sections cover.
Installing a pixel
You can paste the platform's snippet into the page. A tag manager is usually better, because it lets you control when the tag fires, and consent is a gating condition you need.
A simple pattern is to fire the pixel only after consent. The example below shows the shape of that logic without any specific vendor. It uses the consent callback idea from the consent chapter.
function loadAdPixel() {
// Replace this with the vendor's official snippet.
// It is kept as a placeholder so the structure is clear.
var s = document.createElement('script');
s.async = true;
s.src = 'https://example.com/vendor-pixel.js';
document.head.appendChild(s);
}
function onConsentAccepted(choices) {
gtag('consent', 'update', {
analytics_storage: 'granted',
ad_storage: choices.advertising ? 'granted' : 'denied'
});
if (choices.advertising) {
loadAdPixel();
}
}In Google Tag Manager, you get the same result by attaching a consent condition to the pixel tag. Many vendors ship an official template with consent settings built in, and you should prefer those over custom HTML tags.
Reuse your data layer
Do not write a separate tracking call for every platform. Push one event to the data layer and let the tag manager translate it:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'generate_lead',
form_id: 'newsletter_footer',
value: 25,
currency: 'USD'
});In the tag manager, create one trigger on the generate_lead event. Attach it to the GA4 event tag, the Meta Lead tag, and the TikTok SubmitForm tag. You now have one source of truth in the code and several consumers. Adding or removing a platform becomes a tag manager change, not a code deployment.
Deduplication
If you send the same conversion through the browser pixel and through a server-side connection, the platform sees it twice unless you tell it they are the same event. The fix is a shared event ID. You generate a unique value once, send it with both copies, and the platform keeps one.
const eventId = crypto.randomUUID();
window.dataLayer.push({
event: 'generate_lead',
event_id: eventId,
value: 25,
currency: 'USD'
});
// Send the same event_id to your server so the server-side copy can reuse it.Without this step, reported conversions inflate, and the platform's optimization learns from false data.
Preserving click IDs through the funnel
The click ID is in the URL only on the landing page. If the conversion happens two pages later, the pixel needs to remember it. Pixels generally do this with cookies. Some situations break that:
- The visitor lands on
www.example.comand converts on a checkout subdomain or a different domain. First-party cookies set on one host may not be readable on the other. - A browser limits cookie lifetime. Safari's tracking prevention can cap script-set cookies to a short life, so a click ID can expire before a delayed purchase.
- The visitor denied advertising consent, so no cookie is written.
If you want to keep the click ID yourself, for example to attach it to a CRM record, store it the same way you stored UTM values. This version keeps both:
const params = new URLSearchParams(window.location.search);
const keys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'fbclid', 'ttclid', 'gclid'];
const saved = JSON.parse(sessionStorage.getItem('ad_params') || '{}');
keys.forEach(function (k) {
if (params.get(k)) saved[k] = params.get(k);
});
if (Object.keys(saved).length > 0) {
sessionStorage.setItem('ad_params', JSON.stringify(saved));
}sessionStorage is cleared when the tab closes. If you need longer memory, you would use a first-party cookie, and that requires consent in many regions. Store click IDs only when your consent setup allows it.
Why platform numbers and GA4 numbers differ
Expect the Meta dashboard and GA4 to disagree. Both can be correct under their own rules. The usual causes:
- Attribution windows. Ad platforms often credit a conversion to an ad if the person viewed it within one day or clicked it within seven days. GA4's standard reports credit by session and traffic source, and they do not count views.
- View-through conversions. A person sees an ad, does not click, and later converts by another route. The platform may claim it. GA4 sees the visit as direct or organic.
- Different credit rules. A platform tends to claim every conversion it touched. GA4 uses its own attribution model and gives credit to one channel.
- Consent and blockers. The two tools may be blocked at different rates. A user can accept analytics but refuse advertising, or the reverse.
- In-app browsers. Clicks may open inside the social app, where cookies and scripts behave differently from a normal browser.
- Modeled conversions. Platforms estimate conversions they cannot observe. These estimates appear in the platform's report and do not appear in your raw GA4 data.
- Time zones and reporting delay. Conversions are placed on the click day in one tool and the conversion day in another.
The right question is not "which is correct" but "what is each number for." Use the platform's figure to judge delivery and bidding inside that platform. Use GA4 and your own back-end records to compare channels with each other.
Common errors
- Auto-tagging a platform and also hand-tagging with different UTMs, leading to two labels for one campaign.
- Firing the pixel before consent is known.
- Sending a
Purchaseevent with a missing or textvalue, such as"25 USD", instead of a number and a currency code. - Using custom event names instead of the platform's standard names, so the optimizer cannot use them.
- Firing the conversion on page load of a thank-you page. A refresh then counts twice.
- Stripping query strings in a redirect, which removes the click ID before the pixel reads it.
Checking your work
Each platform offers a debug helper. Meta has the Pixel Helper browser extension and a Test Events tool in Events Manager. TikTok has the Pixel Helper and a test events view. Use them alongside the GA4 DebugView you already know. A good test run goes like this:
- Open a landing URL that includes a test click ID parameter.
- Accept the advertising consent option.
- Confirm the page view reaches the platform, and confirm it carries the click ID.
- Complete the conversion.
- Confirm exactly one conversion event arrives, with the right value, currency, and event ID.
- Repeat with advertising consent denied, and confirm nothing is sent to the ad platform.
Exercise
A visitor clicks a Meta ad, lands on your site, and buys two days later after returning from a bookmark. Meta reports the purchase. GA4 attributes it to direct. Give two reasons the numbers can differ in this case, and name one setting or practice that could improve the match.
Show answer
Meta credits the purchase using the click ID and its seven-day click window, so the earlier ad click still counts. GA4 sees the later session as a new visit with no UTM parameters, so it files it under direct. Another valid reason is that the visitor may have returned in a different browser or session where the click ID cookie had expired. To improve the match, store the click ID or UTM values in a first-party cookie, where consent allows it, and send the conversion with the click ID from your server so the platform can match it. Using one shared event ID prevents double counting when you send both browser and server copies.
Exercise
You push a single generate_lead event to the data layer, and the tag manager fires both a GA4 tag and a Meta Lead tag. Later you also add a server-side Lead event. What must you add so Meta does not count each lead twice?
Show answer
Generate one unique event ID per lead, send it with both the browser event and the server event, and keep it identical in both. Meta then deduplicates the two copies into one conversion.