Skip to main content
Server-Side Tracking · 2 min read

Pure Webhook Server-Side Tracking: Sending Stripe Webhooks to GA4 Measurement Protocol

How to track verified Stripe Checkout payments and recurring SaaS subscriptions directly from backend webhooks to GA4 Measurement Protocol without relying on browser thank-you pages.

Syed Yasir

Syed Yasir

Conversion Tracking & Server-Side Attribution Expert

Pure webhook server-side tracking pipeline sending verified Stripe payment events to GA4 Measurement Protocol

Browser-based purchase tracking has an unavoidable flaw: if a customer closes the tab during a 3D Secure bank redirect, or if a SaaS subscription renews 30 days later while the user is asleep, no browser pixel ever fires.

Pure webhook server-side tracking solves this by triggering conversions directly from your payment provider’s authoritative backend event—such as Stripe’s checkout.session.completed or invoice.paid webhook—straight into GA4 Measurement Protocol (or Server-Side GTM).

The Secret to Preserving Attribution: Store client_id & session_id

The #1 mistake developers make with GA4 Measurement Protocol is sending a webhook with a random client_id and no session_id. That causes every webhook purchase to appear under Direct / Unassigned in GA4.

To stitch a backend Stripe webhook back to the original ad click and session:

  1. At checkout creation, read the visitor’s GA4 client_id (from _ga) and ga_session_id (from _ga_<CONTAINER_ID>) and store them in Stripe Checkout metadata (alongside gclid if present).
  2. When Stripe fires checkout.session.completed, your webhook handler reads session.metadata.ga_client_id and session.metadata.ga_session_id and attaches them to the Measurement Protocol payload.
// Server-side webhook handler sending a verified Stripe purchase to GA4 Measurement Protocol
const endpoint = `https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`;

const body = {
  client_id: stripeSession.metadata.ga_client_id,
  events: [
    {
      name: 'purchase',
      params: {
        session_id: Number(stripeSession.metadata.ga_session_id),
        engagement_time_msec: 100,
        transaction_id: stripeSession.id,
        currency: stripeSession.currency.toUpperCase(),
        value: stripeSession.amount_total / 100,
      },
    },
  ],
};

await fetch(endpoint, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(body),
});

Separating Initial Purchases From Recurring Renewals

For SaaS Conversion Tracking, avoid mixing initial acquisition revenue with monthly renewals under the same purchase event unless clearly segmented:

  • Fire purchase on checkout.session.completed (first paid conversion).
  • Fire a distinct custom event such as subscription_renewal on subsequent invoice.paid webhooks so acquisition ROAS stays accurate while LTV reporting remains complete.

Avoiding Duplicate Revenue

If you send purchase via Stripe webhooks, disable your browser thank-you-page purchase tag for GA4—or ensure both share the exact same transaction_id so GA4 deduplicates identical transactions automatically.

Need help implementing resilient Stripe or SaaS webhook tracking? View our Stripe Conversion Tracking service or book a free tracking audit.

Topics: Webhooks Stripe GA4 Measurement Protocol SaaS Tracking
Share this article

Free Tracking Audit

Want Me to Audit Your Conversion Tracking Stack?

Book a free tracking audit. I'll review your GTM, GA4, Server-Side Tracking, Meta CAPI, Google Ads Enhanced Conversions, and Consent Mode V2 setup and highlight exactly what to fix.

Keep Reading

All articles →
Syed Yasir Chat on WhatsApp Available now · Replies under 5 min