How to track purchases without a thank-you page: Stripe payments on the same page
With Stripe's payment form embedded in the page, there is no thank-you URL and the order exists before it is paid. How to send a reliable purchase event to Meta and GA4.
6 min read
In this article
The usual advice is simple: fire the purchase event on the thank-you page. But when Stripe's payment form (Payment Element) is embedded right in the page, the visitor never leaves it, and there is no separate "thank you" URL. Purchases in Meta and GA4 then either do not count at all or get counted together with unpaid orders. This article describes the setup we recently launched on a website with bookings and Stripe payments — and the mistakes we made along the way.
Why "order created" does not mean "paid"
With an embedded Stripe form, the flow usually goes like this: the visitor fills in their details, clicks a button, and the site creates a booking or order in the background (an AJAX request). The response contains a client_secret — the key that lets the Stripe form process this particular payment. Only then does the visitor enter their card details and pay.
So the successful "created" response arrives before the payment. If you fire purchase at that moment, ad platforms will count both people who never entered a card and people whose payment failed. And when your ads optimise for purchases, they will learn from bad data.
The reliable signal: the return to return_url
The Stripe form confirms the payment with stripe.confirmPayment, which takes a return_url. If your code does not include redirect: 'if_required', then after confirmation Stripe always reloads the page to that address and appends the payment_intent and redirect_status parameters — succeeded or failed. That is your thank-you page: the same address, just with a parameter you can read reliably.
Two caveats:
- A card that is declined immediately does not lead to
return_url— Stripe shows the error in the form itself and the visitor can try again. No purchase is fired in that case. - If your code includes
redirect: 'if_required', card payments do not reload the page. Then the signal is the result ofconfirmPaymentitself: fire purchase when the returned payment has the statussucceeded.
The setup step by step
- Order created. Only an internal log event is sent (ours is called "booking"), and a "pending" entry with the order ID and amount is written to the browser's
sessionStorage. redirect_status=succeededcomes back, or the confirmation block is visible on the page. Only then is purchase fired, with the data from the "pending" entry: amount (value), currency (currency) and order ID (calledtransaction_idin GA4). Meta requires value and currency for a purchase event.- Duplicate protection. After purchase is sent,
localStoragerecords that this order ID has already been seen. Reloading the page or going back with the browser button does not fire a second purchase. failedcomes back. The log records "failed". No purchase is fired, but you can see how many people tried to pay and did not.
Why two different storage types? "Pending" only matters in this tab during this visit, so sessionStorage fits. "Already seen" must last longer — even if the visitor reopens the same confirmation URL from their browser history the next day.
Take the amount from data, not from page text
The temptation is strong: the amount is right there on the page, so why not read it? Because it is fragile. That is exactly what we did at first — and we read the wrong block: the label on the page was "Viso kaina" (total price), not "Viso suma" (total amount), which is what we were looking for. All it takes is someone changing one word, or a plugin update changing the page structure, and the conversion value silently becomes wrong.
The fix is to take the amount from the data layer — from the response that returned the newly created order — and store it in the "pending" entry along with the ID. Page text is for people, not for analytics.
There is a second problem too: a Lithuanian page writes the amount as "45,00 €", while analytics needs the number 45.00. A decimal comma instead of a point, plus a currency sign, are two more places where reading the page can silently go wrong.
Every payment path, not just the card
A card form on the page is often not the only way to pay:
- PayPal — a classic redirect: the visitor leaves for PayPal and comes back. The return page follows the same logic: "pending" entry, confirmation, duplicate protection.
- Payment links that an admin sends to a customer, for example after taking a booking by phone. This is the third path. There is no "pending" entry in the browser here, so the ID and amount come from the confirmation page's own data.
Leave any path uncovered and ad platforms will miss part of your purchases. When you commission this kind of work, list every path in the software brief — otherwise it is easy to end up covering only the first one.
How to test without charging real money
Test each payment path separately — card, PayPal and payment link — because each one has its own return point.
- Stripe test mode with test cards is the safest option. If you cannot switch it on for the site, buy the cheapest real product or service.
- Careful with Stripe Link. In the browser, Link may offer your saved card in a single click, which makes it very easy to accidentally charge real money while testing. Before pressing the pay button, check which card is selected.
- Where to look. Meta Events Manager under "Test events", and GA4 DebugView or the Realtime report. The event should appear once, with the correct amount and order ID.
- Your own log. We saw the first real purchase in our log as a pair: "booking" → "purchase" about 4 seconds later. Look for exactly these pairs. If "booking" keeps appearing without a purchase while Stripe shows payments, the chain is breaking somewhere.
If you would like us to set this up on your website, see our website service page.
What to do tomorrow
- Check when your purchase event fires today: when the order is created or after it is paid.
- Find
stripe.confirmPaymentin your code and see whether it includesredirect: 'if_required'— that decides where to catch the signal. - List every way a customer can pay and check, for each one, that purchase fires exactly once.
Frequently asked questions
Can purchase be sent from the server instead of the browser?
Yes — through the Meta Conversions API or the GA4 Measurement Protocol, triggered by a Stripe webhook for a successful payment. It is more reliable but more complex: if the event is sent from both the browser and the server, Meta needs a shared event ID so the purchase is not counted twice. The browser setup is a good first step.
Why not fire purchase when "Pay" is clicked?
A click is not a payment: the card can be declined, the bank can ask for extra verification, the visitor can close the window. Purchase should mean money received, not an intention.
How can I see how many payments failed?
From your own log: "failed" entries, plus "booking" entries with no matching purchase. Compare their number with successful purchases and you will see whether something is getting stuck at the payment step.