Server-Side Tagging9 min read
Stripe Checkout Conversion Tracking: Recording Purchases in GA4, Google Ads and Meta When Buyers Don't Return
Stripe says customers aren't guaranteed to reach your success page, so a purchase tag on that page will miss sales. This guide explains, from Stripe's and Google's documentation, how to track Stripe purchases reliably with webhooks and server-side events.
Why the success page misses purchases
Stripe's fulfilment guide says you can't rely on triggering fulfilment only from your checkout landing page, because it's not guaranteed that customers visit it. Its redirect guide gives an example: a customer pays, then loses their connection before the page loads.
Tracking has the same weakness. A GA4 purchase event, Google Ads conversion tag or Meta Pixel Purchase on the success page only fires for buyers who load that page. For Payment Links the gap can be larger, because Stripe shows its own confirmation message by default and doesn't send the buyer back to your site unless you set a redirect.
Related: Stripe: Fulfill orders · Stripe: Customize redirect behavior
Pass the Checkout Session ID back to your site
Stripe replaces the literal text {CHECKOUT_SESSION_ID} in your redirect URL with the real session ID after payment. Stripe says to add it exactly as written and not substitute the ID yourself. The same placeholder works in the success_url of hosted Checkout, the return_url of embedded Checkout and the after-completion redirect URL of Payment Links.
With the session ID on the success page, your server can retrieve the session and show the order. For tracking, it gives you one ID that the browser and your server both know, which is what deduplication needs.
Stripe's funnel guide also stores the Google Analytics client ID in the Checkout Session metadata, so the server can link the purchase to the visit. We store the visitor's consent choice the same way, because the webhook runs on your server and can't see the cookie banner.
const session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [{ price: "price_123", quantity: 1 }],
// Stripe fills in the real ID after payment. Keep the braces as written.
success_url: "https://example.com/thank-you?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "https://example.com/pricing",
// Values the browser sent with the checkout request (see below).
metadata: {
ga_client_id: gaClientId,
analytics_consent: analyticsConsent, // "granted" or "denied"
ads_consent: adsConsent, // "granted" or "denied"
},
});
// In the browser, before calling your server:
// gtag("get", "G-XXXXXXXXXX", "client_id", (id) => { /* send id with the request */ });
// The callback receives undefined if the Google tag hasn't set a client ID.Related: Stripe: Customize redirect behavior
Payment Links: turn on the redirect
In the Stripe Dashboard, open the payment link's After payment settings and choose not to show the confirmation page, then enter your URL with {CHECKOUT_SESSION_ID} in it. Through the API, set after_completion type to redirect with the same URL.
Stripe's Payment Links page also says UTM codes added to the payment link URL are automatically added to your redirect URL when the customer completes a payment. That keeps campaign parameters on the return visit.
Payment Links create the Checkout Session for you, so you can't add the GA4 client ID to its metadata as shown below. The server-side purchase still records the sale, but GA4 may not tie it to the original visit.
Related: Stripe: After a payment link payment
Keep GA4 from crediting Stripe as the source
When the buyer returns from checkout.stripe.com, GA4 can treat Stripe as a new referral and credit the sale to it. Stripe's conversion funnel guide tells you to add checkout.stripe.com to your referral exclusion list. In GA4 this is List unwanted referrals: Admin, Data streams, your web stream, Configure tag settings, Show all, then List unwanted referrals. Google says you need the Editor role or above, and each data stream takes up to 50 entries.
Stripe's guide also fires a begin_checkout event in the browser before redirecting to Checkout, so you can see how many people start checkout against how many finish.
Record the purchase from Stripe's webhook
Stripe creates a checkout.session.completed event when someone pays. For payment methods that confirm later, it sends checkout.session.async_payment_succeeded when the payment succeeds. Stripe's conversion funnel guide suggests recording the purchase metric whenever you get the checkout.session.completed event in your webhook handler. Check payment_status before you count it: Stripe's fulfilment sample skips sessions that are still unpaid, which is the case for a delayed payment method until checkout.session.async_payment_succeeded arrives.
For GA4, send a purchase event with the Measurement Protocol. Google says the api_secret must stay private and out of client-side code, and that client_id should match the ID generated by the Google Analytics tag on your website. That is why the example above stores it in the session metadata. GA4's purchase event needs transaction_id and items, and currency whenever you send value.
We only send the GA4 event when the visitor accepted analytics cookies, and we pass their advertising choice in the request's consent field, which takes ad_user_data and ad_personalization. Your consent banner and legal advice decide the exact rule for your site.
// Runs on your server after verifying the Stripe signature.
if (event.type === "checkout.session.completed" ||
event.type === "checkout.session.async_payment_succeeded") {
// Retrieve the session with its line items, as Stripe's fulfilment guide does.
const session = await stripe.checkout.sessions.retrieve(
event.data.object.id,
{ expand: ["line_items"] },
);
// Stripe's sample skips unpaid sessions. A delayed payment method is
// unpaid at checkout.session.completed and paid at async_payment_succeeded.
if (session.payment_status === "unpaid") return;
if (await alreadyTracked(session.id)) return;
// Respect the choice the visitor made in your cookie banner.
if (session.metadata.analytics_consent !== "granted") return;
// GA4 needs a client_id. Without one (for example, the tag was blocked),
// skip GA4 here and rely on your other platforms for this sale.
if (!session.metadata.ga_client_id) return;
// Stripe amounts are in the smallest currency unit, for example cents.
// Divide by 100 only for two-decimal currencies.
const toMajor = (amount) => amount / 100;
const adsConsent = session.metadata.ads_consent === "granted" ? "GRANTED" : "DENIED";
const url = "https://www.google-analytics.com/mp/collect" +
`?measurement_id=${process.env.GA4_MEASUREMENT_ID}` +
`&api_secret=${process.env.GA4_API_SECRET}`;
await fetch(url, {
method: "POST",
body: JSON.stringify({
client_id: session.metadata.ga_client_id,
consent: { ad_user_data: adsConsent, ad_personalization: adsConsent },
events: [{
name: "purchase",
params: {
transaction_id: session.id,
value: toMajor(session.amount_total),
currency: session.currency.toUpperCase(),
items: session.line_items.data.map((line) => ({
item_id: line.price.id,
item_name: line.description,
price: toMajor(line.amount_total) / line.quantity,
quantity: line.quantity,
})),
},
}],
}),
});
await markTracked(session.id);
}Related: Stripe: Fulfill orders · Google: Send Measurement Protocol events · Google: Validate Measurement Protocol events
Send it once, even when the webhook arrives twice
Stripe warns that your fulfilment function might be called multiple times, possibly concurrently, for the same Checkout Session, and asks you to make it safe to run more than once. Treat tracking the same way: store which session IDs you have already sent, as the example does with alreadyTracked and markTracked.
If you also fire a purchase in the browser on the success page, use the same transaction_id in both. Google's GA4 event reference says transaction_id helps you avoid duplicate events for a purchase.
Timing limits for server-side GA4 events
Google's Measurement Protocol documentation says events can be backdated up to 72 hours. It also says events should arrive within 48 hours of the original client-side event to be joined with it or used for conversion attribution.
Webhooks usually arrive within seconds, so this matters mainly for delayed payment methods that confirm days later. For those, send the purchase when the payment succeeds, and expect GA4 to attribute some of them less precisely. Google says an event with a timestamp older than 72 hours is accepted with its time moved to 72 hours ago, unless you ask for strict validation.
Google Ads and Meta
Google's Measurement Protocol pages don't describe Measurement Protocol events being attributed to Google Ads clicks, so we don't rely on that. For Google Ads we store the click ID with the order and send the paid order as an offline conversion, or use a Google Ads tag on the success page where most buyers return. For Meta we send a Purchase through the Conversions API from the same webhook, with the session ID as the event ID shared with any Pixel Purchase.
Whichever platforms you send to, use one ID for the order everywhere. The Checkout Session ID works well, because Stripe puts it in the success URL and in the webhook.
Related: Our guide: Google Ads offline conversion import in 2026 · Our guide: Meta Pixel and Conversions API duplicate events
Sources
The Stripe behaviour above comes from Stripe's documentation, and the Measurement Protocol rules from Google's developer documentation, checked on 30 November 2026. Stripe's own sample sends its linked purchase to Google's older /batch endpoint with Universal Analytics style parameters, so use the GA4 Measurement Protocol format shown here. Google also says the Measurement Protocol is a finalized product with no plans for deprecation, and recommends its Data Manager API for new server-to-server integrations.
Related: Stripe: Analyze your conversion funnel · Stripe: Customize redirect behavior · Stripe: Fulfill orders · Stripe: After a payment link payment · Google: Send Measurement Protocol events · Google: Measurement Protocol reference · Google: Validate Measurement Protocol events
Problems and fixes
1Fewer purchases in GA4 than in Stripe
- Symptom
- Stripe shows more paid sessions than GA4 shows purchases.
- Cause
- Buyers don't reach the success page, Payment Links show Stripe's confirmation page, or delayed payments confirm later.
- Fix
- Send the purchase from the webhook, and turn on the Payment Links redirect.
2Sales credited to checkout.stripe.com
- Symptom
- GA4 shows Stripe as the referral source for purchases.
- Cause
- The return from Stripe's checkout starts a new referral.
- Fix
- Add checkout.stripe.com to List unwanted referrals under Configure tag settings for your web stream.
3Purchases counted twice
- Symptom
- GA4 revenue is higher than Stripe's.
- Cause
- The webhook ran more than once, or the browser and server purchases use different transaction IDs.
- Fix
- Record which sessions you've sent, and use the Checkout Session ID as transaction_id on both sides.
4Server purchases show as a separate, unattributed user
- Symptom
- Purchases arrive but with no source or campaign.
- Cause
- The Measurement Protocol event uses a client_id that doesn't match the Google tag's ID.
- Fix
- Read the GA4 client ID in the browser before checkout, store it in the session metadata, and send it from the webhook.
Implementation Checklist
Verify each milestone before deploying changes to live production ad accounts.
- ✓{CHECKOUT_SESSION_ID} in success_url, return_url or the Payment Links redirect
- ✓Payment Links set to redirect, not show Stripe's confirmation page
- ✓checkout.stripe.com in List unwanted referrals
- ✓GA4 client ID stored in the session metadata
- ✓Webhook handles checkout.session.completed and async_payment_succeeded
- ✓Unpaid sessions skipped, delayed payments counted on async_payment_succeeded
- ✓GA4 event sent only with analytics consent, ad consent passed through
- ✓Each session sent once, with the session ID as transaction_id
- ✓Payload tested on the Measurement Protocol validation server
Frequently asked questions
Can I track Stripe Checkout purchases with a tag on the success page?
You can, but Stripe says customers aren't guaranteed to visit that page, so some purchases will be missed. Use the checkout.session.completed webhook as well.
How do I get the Checkout Session ID on my thank-you page?
Add the literal text {CHECKOUT_SESSION_ID} to the success URL. Stripe replaces it with the real session ID after payment.
Do Stripe Payment Links send buyers back to my site?
Not by default. Stripe shows a confirmation page unless you choose to redirect, in the link's after-payment settings or with after_completion in the API.
Which Stripe webhook events mean a purchase?
checkout.session.completed when someone pays, and checkout.session.async_payment_succeeded when a delayed payment method succeeds later.
How long after a sale can I send it to GA4?
Google says Measurement Protocol events can be backdated up to 72 hours, and should arrive within 48 hours of the original client-side event to be joined with it.
Need a hand with this?
Want us to set this up for you?
This is the kind of work we do for clients every week. Tell us about your setup and we'll take it from there.
Keep reading
How to Import GA4 Key Events into Google Ads as Conversions, and the Settings That Decide What Bidding Sees
Google Ads can use your GA4 key events as conversions, but the import has prerequisites, a default that keeps new actions out of bidding, and settings that only one of the two tools can change. This guide walks through it from Google's help pages.
GoHighLevel All-in-One Platform: Every Feature, the Real Monthly Cost, and How to Set It Up (2026)
Most small businesses and agencies pay for a CRM, a funnel builder, an email tool, a scheduler, an SMS app and a review tool, then copy leads between them by hand. This guide walks through every part of GoHighLevel, what it really costs per month with usage, how it compares with ClickFunnels and Kajabi, and a 14-step setup from free trial to tracked ads.
WooCommerce GA4 Purchase Tracking: How the Google Analytics Extension Works and Where Sales Go Missing
The Google Analytics for WooCommerce extension sends purchases and shopping events to GA4, but only under certain conditions. This guide explains how it works from WooCommerce's own documentation, why some sales never reach GA4, and how we close the gaps.