How to track purchases and revenue in Google Analytics 4
Send GA4's purchase event with a value, currency and transaction ID, including after Stripe Checkout or Payment Links, so GA4 shows sales and revenue by source.
To count sales and revenue in Google Analytics 4, send the recommended purchase event when a payment succeeds, with transaction_id, value and currency. GA4 then shows purchases and revenue by source and landing page, and the transaction ID stops the same sale being counted twice.
The purchase event
Run this on the page people see after paying, once per payment:
gtag("event", "purchase", {
transaction_id: "T_12345", // your order or Stripe session ID
value: 29.0, // the amount paid
currency: "USD", // ISO currency code
items: [{ item_id: "pro-monthly", item_name: "Pro (monthly)", price: 29.0, quantity: 1 }],
});transaction_idmust be unique per sale. GA4 drops a second purchase with the same ID, so a reload of the thank-you page doesn't double-count.valueandcurrencygive GA4 the revenue. Without them you get a purchase count but no revenue.itemsis optional for a simple product, but GA4's ecommerce reports use it.
Then mark purchase as a key event: Admin → Data display → Events → Mark as key event. How.
After Stripe Checkout
Stripe Checkout sends buyers to your success_url. Add the session ID to it, then send the purchase event on that page:
- When creating the Checkout Session, set
success_urlto something likehttps://mysite.com/thank-you?session_id={CHECKOUT_SESSION_ID}. Stripe fills in the ID. - On the thank-you page, use the
session_idas thetransaction_id, and the amount (from your server, or a fixed price) asvalue.
After a Stripe Payment Link
In Stripe, edit the Payment Link → After payment → Don't show confirmation page → redirect to your own page, for example https://mysite.com/thank-you?session_id={CHECKOUT_SESSION_ID}. Then send the purchase event there, as above.
Can't add code to the thank-you page?
Count views of it as sales instead. It's less precise (no revenue, and a reload counts again), but it needs no code: count sales from a thank-you page.
Fix this first: payment pages taking the credit
When buyers go to checkout.stripe.com and come back, GA4 may credit the sale to Stripe instead of the place the buyer first came from. List payment pages as unwanted referrals before you trust revenue by source.
Related
Sources
- Google: Measure ecommerce: purchase
- Stripe: Customize redirect behavior
Last updated
Track signups
Two ways to count signups in GA4: send a sign_up event from your code, or create one from your welcome page with no code at all. Then mark it as a key event.
Thank-you page conversions
No purchase event? Count sales or signups from views of your thank-you page: create a GA4 event from page_view, mark it as a key event, and know its limits.