Search
Contact salesTry for free

Stripe purchase tracking via sGTM: a step-by-step guide

Kristian Krogh Bang

Kristian Krogh Bang

Author
Published
Apr 16, 2026

If you use Stripe Checkout or Payment Links, you have a tracking problem.

The checkout happens on Stripe's domain. Your pixels never see it. The customer lands on your thank-you page, and all you have is a session ID – no revenue, no items, no customer data, no cookies, no browser context.

Most solutions make it worse. Webhooks give you order data but zero session context. Node.js proxies require infrastructure you shouldn't need. Zapier workflows give you partial data at best. And some blog posts suggest exposing your Stripe secret key client-side – don't do that.

There is a better way.

Purchase tracking flow via sGTM

One sGTM client template + one JS snippet on your thank-you page. That's the entire setup.

Here is the full flow:

  1. Customer completes payment on Stripe and lands on your thank-you page with ?session_id={CHECKOUT_SESSION_ID} in the URL.
  2. The JS snippet reads the session ID, collects 30+ ad platform cookies (including Stape cookies), and POSTs everything to your sGTM container hosted on Stape.
  3. The sGTM client template calls the Stripe API server-side with your secret key.
  4. Stripe returns the full session – line items, customer details, tax, discounts, and payment status.
  5. The template builds a complete GA4 purchase event and fires all your sGTM tags with the enriched data.

Your Stripe secret key never leaves the server. The browser only sends the session ID and cookies.

The key difference from webhooks: because the request comes from the customer's browser on your thank-you page, you get real session context. GA4 sees the purchase as part of the same session. No orphaned conversions.

What data is extracted per purchase event

The template extracts everything useful from the Stripe session and maps it to GA4 and Meta CAPI format: _epik

CategoryFields
Ecommercetransaction_id, value, currency, tax, shipping, coupon, payment_type, items[]
User dataEmail, phone, first name, last name, billing address, business name
Session stitchingclient_id, ga_session_id, ga_session_number, ip_override,user_agent, page_location, page_referrer
ConsentGoogle Consent State, DMA flag, no-personalized-ads signal
Ad platform cookies_ga, _fbp, _fbc, _ttp, li_fat_id, _gcl_aw, _epik, Klaviyo, affiliate networks, and more

Step-by-step setup

Taking it further with Stape

Because this setup runs on Stape, you can easily extend it with features that are otherwise complex to build.

The JS snippet natively collects Stape cookies and 30+ ad platform cookies. If you want to go further, Stape's Cookie Keeper power-up extends the lifespan of those cookies to 2 years, protecting attribution against Safari's ITP restrictions, which otherwise expire client-side cookies in 1-7 days.

Track new vs. returning customers with Stape Store

Hash the customer's email at purchase time and store it as a document key in Stape Store with a purchase_count. 

On the next purchase, look it up: 

  • If the key doesn't exist, it's a new customer.
  • If purchase_count is 1 or higher, it's a returning customer. 

You can send this signal directly to Google Ads and Meta, significantly improving bidding efficiency. 

Read the full guide on Stape Store customer tracking.

Re-stitch subsequent purchases and handle cancellations

Store the original session stitching data (client ID, session ID, etc.) in Stape Store alongside the hashed email. When the same customer makes a subsequent purchase – an upsell, a renewal, a repeat order – you can retrieve that data and re-stitch the new event into the correct user journey, even without a live browser session.

For cancellations and refunds, Google Ads is the only major platform that supports post-conversion adjustments. Store the transaction_id at purchase time and use the Google Ads Conversion Adjustments tag to retract or reduce the value when an order is canceled.

i

The template is open source under the Apache 2.0 license. You can find the full code and setup instructions in the GitHub repository.

author

Kristian Krogh Bang

Author

Kristian Krogh Bang is a tracking infrastructure specialist and Stape Partner with 5+ years of experience and 100+ setups delivered.

Comments

Try Stape for all things server-side

What’s going on?

Where are we going?

Attention!
This is a stand-up dog zone.