Grosslytics

How to Track Stripe Revenue by UTM & Traffic Source

Connect Stripe Checkout and Payment Links to UTMs and visitor sources, configure signed webhooks, and track fees, renewals, and refunds in Grosslytics.

Pass the Grosslytics visitor ID (gl_vid) into Stripe Checkout as client_reference_id and point Stripe’s signed webhooks at Grosslytics. On your pages, g.js tags Stripe Payment Links automatically; on server-created Checkout Sessions, pass visitor_id in session and subscription metadata so initial sales, renewals, and refunds credit the traffic source.

Key takeaways

  • Keep the same visitor ID (gl_vid) on the landing page and the Stripe checkout; a UTM on the success page alone loses the first-touch channel.
  • Payment Links use client_reference_id; server-created subscriptions should also attach visitor_id to subscription_data.metadata for renewal invoices.
  • Configure snapshot webhook payloads in Stripe and test both initial checkouts and subscription renewals against your webhook API version.
  • Grosslytics deducts successful partial and full Stripe refunds. It imports Stripe’s reported processing fees where available and labels estimates.

What do you need before connecting Stripe?

You need a tracked website, a Grosslytics site ID, a working Stripe checkout, and a reachable webhook endpoint.

This guide follows Stripe’s documentation and the Grosslytics webhook handler. Before turning it on for production traffic, run one test-mode purchase and inspect the recorded source in your dashboard.

  1. Add your site in the Grosslytics setup wizard.
  2. Set the site’s reporting currency to match your Stripe charges.
  3. Choose Payment Links or server-created Checkout Sessions.
  4. Confirm your Grosslytics API URL is reachable by Stripe webhooks.
  5. Stay in Stripe test mode until one test purchase credits the expected source.

See the tracker installation guide for Content Security Policy headers and self-hosted API routing. Comparing Stripe analytics tools? See our DataFast alternatives guide.

Step 1: How do you record the visit and carry its identity?

Install g.js on your acquisition pages so every visit generates a visitor ID before the user clicks checkout.

<script defer src="https://grosslytics.com/g.js"
  data-site-id="YOUR_SITE_ID"></script>

<a href="https://buy.stripe.com/YOUR_PAYMENT_LINK">Subscribe</a>

Replace the placeholders and, when self-hosting, point src to your own analytics hostname. When client_reference_id is absent on a buy.stripe.com link, g.js appends it and leaves any existing client_reference_id untouched.

For server-created Checkout Sessions, read the visitor ID from browser storage after g.js loads and send it with your checkout request:

// Browser: run from your checkout button after the page loads.
let visitorId = null;
try { visitorId = localStorage.getItem('gl_vid'); } catch {}

const response = await fetch('/api/checkout', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ visitorId })
});
if (!response.ok) throw new Error('Checkout could not be created.');
const { url } = await response.json();
window.location.assign(url);

If gl_vid is unavailable (for example, strict storage blocking), let checkout proceed so you never block a customer purchase.

Step 2: How do you attach the ID to Stripe Checkout?

For Payment Links, hover the link to confirm ?client_reference_id= is present. For server-created sessions, pass client_reference_id and metadata.visitor_id in stripe.checkout.sessions.create().

Stripe passes client_reference_id to checkout.session.completed, which handles the initial purchase. For recurring subscriptions, also set subscription_data.metadata so downstream renewal invoices stay linked to the buyer. Source: Stripe Payment Link URL parameters.

Stripe documentation showing client_reference_id for Payment Link reconciliation.
Public Stripe documentation for the client reference field used to connect a Payment Link checkout to a visitor. Captured 2026-11-08. Source: Stripe.

Inside your server checkout endpoint:

// Server only: inside your authenticated checkout route.
const visitorId = typeof body.visitorId === 'string'
  && /^[A-Za-z0-9_-]{1,200}$/.test(body.visitorId)
  ? body.visitorId : null;

const session = await stripe.checkout.sessions.create({
  mode: 'subscription',
  line_items: [{ price: process.env.STRIPE_RECURRING_PRICE_ID, quantity: 1 }],
  success_url: 'https://your-site.example/thanks?session_id={CHECKOUT_SESSION_ID}',
  cancel_url: 'https://your-site.example/pricing',
  ...(visitorId ? {
    client_reference_id: visitorId,
    metadata: { visitor_id: visitorId },
    subscription_data: { metadata: { visitor_id: visitorId } }
  } : {})
});
// Return session.url to the browser from your framework's response handler.

For a one-time payment, switch mode to 'payment' and omit subscription_data. Source: Stripe Checkout Session API.

Stripe places subscription metadata on invoices under parent.subscription_details.metadata in newer API versions. Grosslytics reads those fields and invoice.metadata, and falls back to matching returning buyers by email if metadata is absent. Source: Stripe metadata.

Step 3: Which webhook events should you configure?

Send signed snapshot events to the Grosslytics Stripe endpoint and save that destination’s signing secret in Payments settings.

https://YOUR_ANALYTICS_DOMAIN/api/webhooks/stripe?siteId=YOUR_SITE_ID
Event What Grosslytics records What to verify
checkout.session.completed Records the initial checkout when payment_status is paid Visitor reference and net amount
invoice.paid Records invoice payments and marks subscription_cycle as renewal Metadata shape and no duplicate initial charge
invoice_payment.paid Links invoice and PaymentIntent IDs Matching invoice association
checkout.session.async_payment_succeeded Records a delayed payment once it succeeds Original Checkout Session and visitor ID
refund.created, refund.updated, refund.failed Tracks successful partial and full refunds Refund amount and status in the sale details
charge.updated Links charge data, including any balance transaction details on the event Charge reference on the payment

Select Stripe’s snapshot event payload format (not thin payloads) because Grosslytics reads the expanded data.object payload. Source: Stripe webhook configuration.

Grosslytics ignores unpaid sessions until Stripe confirms that the payment succeeded.

How do you test Stripe attribution before launch?

Test one tagged visit through Stripe checkout and reconcile the recorded sale against your Stripe Dashboard event log.

Open a tagged URL in a fresh browser window:

https://your-site.example/blog/track-chatgpt-traffic-revenue/?utm_source=newsletter&utm_medium=email&utm_campaign=launch

Complete a test purchase in the same browser, then confirm the sale credits newsletter, matches your site currency, and appears across first-touch, last-touch, and linear views. For a worked sandbox run with utm_source=chatgpt.com, see our ChatGPT revenue tracking walkthrough.

Grosslytics public demo showing first-touch net revenue, a daily chart and source reports.
Grosslytics public demo with sample data. Captured November 8, 2026. View source page.

The dashboard definitions explain first touch, last touch, and the 50/50 linear split. Because a buyer can read multiple pages before paying, per-page revenue counts each page that participated in the journey rather than splitting a single sale exclusively across pages.

Verified Stripe sandbox example

For November 6-9, 2026 UTC, a Grosslytics sandbox check imported three USD test payments and one refund into a local installation. The export matched Stripe’s Balance Transactions API by charge and refund ID.

USD amounts for November 6-9 Grosslytics audit export Stripe balance activity
Three charges $27.00 $27.00
One refund $9.00 $9.00
Processor fees $1.68 $1.68
Revenue after the refund and fees $16.32 $16.32

Variance was $0.00 across that test-mode window, with the refund landing in the same closed period as the three charges. For your own check, use the same currency, match by charge and refund ID, and account for any refunds that land after the sale period. Stripe Balance report.

See the reconciliation in the demo or open the Stripe payment setup step. For hosted setup, check Cloud availability.

How does Grosslytics calculate net Stripe revenue?

Grosslytics deducts successful refunds and reported sales tax from gross revenue. To calculate net revenue, it subtracts the fee from Stripe’s balance transaction in the site currency when available. Otherwise it labels the fee as estimated.

For a $100 charge with no tax, Grosslytics records $3.20 in estimated fees and $96.80 in net revenue:

estimated_fee = round(10000 * 290 / 10000) + 30 = 320 cents
net_after_estimated_fee = 10000 - 320 = 9680 cents

Because international cards, currency conversion, and Stripe Billing fees vary by region and contract, reconcile totals against your Stripe payout reports before accounting. Each Grosslytics site reports in one currency (USD, EUR, GBP, or INR) and rejects payments in other currencies rather than converting them. You can model fee impacts across gateways with the SaaS payment fee calculator or see how this differs from event-only tools in our Plausible revenue comparison.

What should you check when a Stripe payment is unattributed?

Check these six items whenever a recorded Stripe sale appears under Unattributed:

  1. Confirm g.js returned 202 Accepted on the landing page (check Content Security Policy headers).
  2. Inspect the Checkout link or checkout.sessions.create payload for client_reference_id or metadata.visitor_id.
  3. Verify the webhook signing secret in Grosslytics matches the Stripe endpoint secret.
  4. Check whether the Stripe webhook API version uses parent.subscription_details.metadata for renewals.
  5. Confirm the payment currency matches the site’s reporting currency (mismatches return HTTP 422).
  6. Test in a normal browser tab rather than WebDriver automation, which g.js filters as a bot.

Review the payment integration reference for all supported Stripe parameters and webhook endpoints.

Frequently asked questions

Does client_reference_id automatically track every renewal?

No. It links the initial Checkout Session. Add visitor_id to subscription_data.metadata (or rely on email matching for returning customers) so subsequent invoice.paid events credit the original source.

Yes. When g.js runs on your site, it appends ?client_reference_id=<visitor_id> to any buy.stripe.com link automatically, and Stripe includes that value in the checkout.session.completed webhook.

Does Grosslytics read my exact Stripe processing fee?

Yes, when the balance transaction provides the fee in the site’s currency. In Settings, use Import past Stripe payments to bring those fees into Grosslytics. The sale details show whether the fee came from Stripe or was estimated.

Do these events cover delayed Stripe payment methods?

Instant methods (cards, Apple Pay, Google Pay, Link) complete inside checkout.session.completed with payment_status: "paid". For delayed methods such as ACH or SEPA, include checkout.session.async_payment_succeeded in your Stripe webhook configuration.