BlogGuide

How to send Stripe payments to Google Analytics 4

In this guide, we show you how to record Stripe Checkout payments in Google Analytics 4 from your server, tied to the visit that led to them, in six steps.

GA4 can't see a Stripe payment on its own. The payment happens on Stripe's page, the webhook lands on your server, and the browser that GA4 was watching may never come back to a thank-you page at all.

The dependable way to fix that is to send the purchase from your server with GA4's Measurement Protocol, carrying the visitor's GA client ID through the checkout so the sale lands on the right person. Here are the six steps:

  1. Create an API secret in GA4
  2. Read the GA IDs in the browser
  3. Store them on the Checkout Session
  4. Send the purchase from your webhook
  5. Check it with the validation server
  6. Send refunds and renewals too

Everything here was checked against Google's and Stripe's docs on 12 November 2026. One warning first. Stripe's own guide still links browser and server events through the old Universal Analytics endpoint, which Google has shut down. Use the GA4 request in step 4 instead.

1. Create an API secret in GA4

In GA4, open Admin → Data streams and pick your web stream, then under Measurement Protocol API secrets, click Create and copy the value. You'll also need the stream's measurement ID, the one that starts with G-.

While you're in the stream, open Configure tag settings → List unwanted referrals and add checkout.stripe.com. Otherwise a returning buyer's visit is credited to Stripe.

2. Read the GA IDs in the browser

Your server needs to know which GA4 visitor is paying. The gtag get command returns the client ID and the current session ID, so read both when the checkout button is clicked and send them along:

const GA_ID = 'G-XXXXXXXXXX';

gtag('get', GA_ID, 'client_id', (clientId) => {
  gtag('get', GA_ID, 'session_id', async (sessionId) => {
    const res = await fetch('/api/checkout', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ plan: 'pro', gaClientId: clientId, gaSessionId: String(sessionId) }),
    });
    const { url } = await res.json();
    window.location.href = url;
  });
});

3. Store them on the Checkout Session

On the server, put the two IDs in the session's metadata. Copy them onto the payment or the subscription too, so the refund and renewal events in step 6 can find them later:

const ga = { ga_client_id: req.body.gaClientId, ga_session_id: req.body.gaSessionId };

// A one-off payment
const session = await stripe.checkout.sessions.create({
  mode: 'payment',
  line_items: [{ price: 'price_123', quantity: 1 }],
  metadata: ga,
  payment_intent_data: { metadata: ga },
  success_url: 'https://example.com/thanks',
});

// A subscription: use subscription_data: { metadata: ga } in place of payment_intent_data

This works for Checkout Sessions you create in code. Payment Links and Pricing Tables can't carry a value per visitor this way.

4. Send the purchase from your webhook

Listen for checkout.session.completed. Some payment methods settle later, so only send the purchase once payment_status is paid:

if (event.type === 'checkout.session.completed') {
  const s = event.data.object;
  if (s.payment_status === 'paid') {
    const value = s.amount_total / 100; // not for zero-decimal currencies like JPY

    await fetch(
      `https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`,
      {
        method: 'POST',
        body: JSON.stringify({
          client_id: s.metadata.ga_client_id,
          events: [{
            name: 'purchase',
            params: {
              transaction_id: s.payment_intent ?? s.id,
              value,
              currency: s.currency.toUpperCase(),
              session_id: s.metadata.ga_session_id,
              items: [{ item_name: 'Pro plan', price: value, quantity: 1 }],
            },
          }],
        }),
      },
    );
  }
}

Stripe stores amounts in the smallest unit, so $49.00 arrives as 4900. GA4 wants 49.

The session_id is what ties the sale to the visit, and with it the visit's channel. Google only accepts it within 24 hours of the session starting, which suits Checkout, where people usually pay in the same sitting.

5. Check it with the validation server

The live endpoint never returns an error, even for a broken event, so a typo fails quietly. Send the same body to https://www.google-analytics.com/debug/mp/collect first. It answers with validationMessages, and an empty list means GA4 will accept the event.

Then make a real test payment and watch for it in Reports → Realtime, and if you also fire purchase from a thank-you page, remove one of the two, or every sale is counted twice.

6. Send refunds and renewals too

Refunds. Listen for charge.refunded and send a refund event with the same transaction_id, which is the charge's payment_intent, plus the refunded value and currency. Read the client ID from the PaymentIntent's metadata, where step 3 put it.

Renewals. Each renewal arrives as invoice.paid, weeks or months after the visit. Send it as a purchase with the invoice ID as transaction_id and the client ID from the subscription's metadata. The session is long over by then, so GA4 can count the money against the visitor but can't credit it to the channel that brought them in.

Final thoughts

Sending Stripe payments to GA4 takes six steps:

  1. Create an API secret in GA4
  2. Read the GA IDs in the browser
  3. Store them on the Checkout Session
  4. Send the purchase from your webhook
  5. Check it with the validation server
  6. Send refunds and renewals too

It works, but you own the plumbing: the webhook, the currency maths, the refunds, and renewals that never reach a channel.

Spreelytics, which we make, does this part for you. You connect Stripe once, add two IDs to the checkout, and every payment, renewal and refund is credited to the channel that earned it, on the free plan too. How to see which marketing channel earned each Stripe payment walks through it, and how we compare with GA4 covers the rest.

See your own numbers today.

Free up to 1M events a month · no credit card

Contact

Tell us what you need.

A real person reads these. We usually reply within one working day.

Or email us directly at contact@spreelytics.com.