GA4 & Tracking

How to Keep Ad Click IDs Through a Third-Party Checkout

Webhooks know who paid but not which ad they clicked. Here is how to carry gclid, fbc, fbp and the GA4 client ID through Stripe, PayPal and other checkouts.

Quick answer

When a purchase is sent from a payment webhook, the ad platforms need the visitor's identifiers to credit the right ad. Save the GA4 client ID and session ID, the Google Ads gclid and Meta's _fbc and _fbp before the visitor leaves for the checkout, link them to the payment with an internal reference, and send them with the server-side purchase.

Key takeaways
  • A webhook knows the payment and the customer, not the ad click.
  • Save identifiers on your side before the visitor leaves for the checkout.
  • Link them to the payment with a short internal reference, not personal data.
  • Send the GA4 client ID and session ID, gclid, fbc and fbp with the server purchase.
  • Hashed email from the payment improves matching when click IDs are missing.

Server-side purchase tracking solves one problem and creates another. When Stripe, PayPal or another payment gateway confirms a payment through a webhook, you finally record every sale, even from buyers who closed the tab. But the webhook comes from the payment provider's server, not from the visitor's browser. It has no cookies, no click ID and no idea which ad the buyer clicked. Unless you plan for it, those purchases arrive in GA4 as (not set) or Direct, and Google Ads and Meta cannot credit them to a campaign.

This guide explains how to carry the right identifiers through any third-party checkout. It is the missing piece behind my Stripe and PayPal tracking setups.

Which identifiers do you need to keep?

Each platform matches a purchase to an ad with its own identifiers.

Platform Identifier Where it comes from
GA4 client ID The _ga cookie
GA4 session ID The _ga_<measurement ID> cookie (for example _ga_ABC123XYZ)
Google Ads gclid (also gbraid / wbraid) The landing page URL after an ad click
Meta fbc The _fbc cookie, built from the fbclid URL parameter
Meta fbp The _fbp cookie set by the Meta Pixel
Microsoft Ads msclkid The landing page URL
TikTok ttclid The landing page URL

You do not need all of them, only the ones for the platforms you advertise on, plus GA4.

Step 1: Capture the identifiers before checkout

Read the identifiers in the browser at the moment the visitor starts checkout, while they are still on your site.

  1. Make sure your site keeps click IDs from the landing page. A first-party cookie set on arrival (or the cookies GA4, Google Ads and Meta already set) is the usual source.
  2. When the visitor clicks Buy, read the GA4 client ID and session ID, gclid, _fbc and _fbp.
  3. Respect consent: if the visitor declined advertising cookies, do not collect advertising identifiers. My consent and server-side GTM guide explains how this fits together.

Now attach the identifiers to the payment, so the webhook can find them later. There are two clean patterns.

Pattern A: store them on the payment. If your server creates the payment, add the identifiers directly:

  • Stripe Checkout: add them to the Checkout Session metadata.
  • PayPal Orders: set a custom_id or invoice_id on the order that points to your stored record.

Pattern B: store a reference. Save the identifiers in your own database (or a server-side store) under a short internal ID, and pass only that ID to the checkout:

  • Stripe Payment Links: add client_reference_id to the link URL. Stripe includes it in the checkout.session.completed webhook. It accepts only letters, numbers, dashes and underscores (up to 200 characters), so use an internal ID, not an email.
  • Other gateways: most have a merchant reference or order ID field that comes back in their callback.

Pattern B keeps personal data out of the payment provider and works with almost any gateway.

Step 3: Send them with the server-side purchase

When the webhook arrives in your server-side GTM container (or backend), look up the identifiers and include them in each platform's event:

  1. GA4: send the purchase with the stored client ID and session ID, so it joins the original session and keeps its source.
  2. Google Ads: send the conversion with the gclid, plus hashed email and phone for enhanced conversions. If the conversion happens much later, an offline import with the gclid also works.
  3. Meta: send the Conversions API purchase with fbc, fbp, the client IP and user agent saved at checkout, and hashed email. Use the same event_id as any browser Purchase.
{
  "event_name": "purchase",
  "transaction_id": "cs_live_a1B2c3",
  "value": 199,
  "currency": "USD",
  "ga_client_id": "1234567890.1730419200",
  "ga_session_id": "1730419200",
  "gclid": "EAIaIQobChMI...",
  "fbc": "fb.1.1730419200000.IwAR...",
  "fbp": "fb.1.1730419100000.123456789"
}

What if the identifiers are missing?

Some buyers block cookies, switch devices or arrive without a click ID. You can still help the platforms match:

  • Send hashed email and phone from the payment. Google Ads and Meta both use them for matching.
  • Keep the purchase in GA4 even without a session, so revenue is complete, and accept that its source may be unknown.
  • Do not invent or reuse identifiers from other visitors; that corrupts attribution.

Common mistakes

  • Reading identifiers on the success page, after the visitor has already been away
  • Putting an email address in Stripe client_reference_id (it is silently dropped)
  • Storing identifiers for visitors who declined advertising consent
  • Sending a webhook purchase without the GA4 session ID, so it shows as (not set)
  • Using different transaction IDs in the browser and on the server

If your paid traffic already shows as Direct or Unassigned, read why paid traffic shows as Direct or Unassigned in GA4 as well.

Final thoughts

Server-side purchases are only half the job; attribution is the other half. Save the identifiers before the visitor leaves, link them to the payment with a clean reference and send them with every server event. My conversion tracking service includes this for Stripe, PayPal and other gateways.

Related
Chamok Mahonto
Written by Chamok Mahonto

I'm a conversion tracking & google ads specialist from Rangpur, Bangladesh. I set up GA4, GTM, server-side tracking and Meta Conversion API, and manage Google Ads for businesses worldwide. More about me

FAQ

Frequently asked questions

Why do my server-side purchases show as (not set) in GA4?

Usually because the event does not carry the visitor's GA4 client ID and session ID, so GA4 cannot join it to the original session and its source.

Can I put the gclid in Stripe client_reference_id?

A gclid usually contains only letters, numbers, dashes and underscores, so it can fit. But it is cleaner to store an internal reference there and keep all identifiers in your own database or in session metadata.

Is it allowed to store these identifiers?

Click IDs and analytics IDs are personal data in many regions. Store them only with the visitor's consent where required, keep them only as long as needed, and mention them in your privacy policy.

What if the click ID is missing?

Send hashed email and phone from the payment. Google Ads enhanced conversions and Meta's Conversions API can still match many purchases using that data.

Keep reading

Related articles

GA4 & Tracking

How to Set Up BigCommerce Tracking for GA4, Google Ads and Meta

BigCommerce offers native integrations and Script Manager. Here is how to combine them without double-counting purchases in GA4, Google Ads and Meta.

4 min read · November 2, 2026
GA4 & Tracking

Consent Mode v2 with Server-Side GTM and Meta CAPI: How It Works

Server-side tracking does not remove the need for consent. Here is how consent signals reach your server container and how to make every server tag respect them.

4 min read · November 2, 2026
GA4 & Tracking

Consent Mode v2 Explained: What Small Businesses Must Do

A plain-English guide to Google Consent Mode v2: the four signals, basic vs advanced mode, who needs it, and how to set it up and test it in GTM.

6 min read · October 30, 2026

Ready to fix your tracking and scale your ads?

Get a free audit of your tracking and ad account. Usually replies within 1–2 hours.