virling Pricing Self-host Demo Changelog Agencies GitHub Start free trial
blog / 2026-11-20

Stripe invoice attribution for sales-led B2B SaaS

By Devendra Variya, co-founder of Virling. Published 2026-11-20, updated 2026-11-30.

A Stripe invoice paid days after a demo call can still be credited to the channel that first brought the buyer, as long as the payment can be tied back to a visitor. Virling ties it in one of two ways: a visitor ID carried on the payment, or the payer's email matching an email that visitor shared earlier, for example when they booked the demo. Once the payment has a visitor, Virling looks at that visitor's sessions inside the lookback window before the payment and credits one of them. With the First touch model, that is the earliest one: the channel that brought them in.

Why invoices lose their source

In a sales-led deal the buyer reads a post, books a call, talks to you, and pays an invoice a week later from a link in their inbox. Stripe records who paid and how much. Nothing on that invoice says the buyer first came from a search, a newsletter or a post on Hacker News. The browser that visited your site and the payment that arrived later are two separate records, and something has to join them. Invoices are one part of a longer path; what a small B2B SaaS team can track covers the rest.

Open a matched invoice payment in Virling to see the buyer's visits before it, the one that got the credit and how long they took to pay.

Start free trial See the demo

How Virling matches a Stripe payment

Virling reads Stripe charges with a read-only restricted key. For each charge it looks for a visitor ID in this order:

  • metadata.virling_vid on the charge
  • metadata.virling_vid on its PaymentIntent
  • metadata.virling_vid or client_reference_id on the Checkout Session that created it

An invoice you send from Stripe does not pass through a Checkout Session on your site, so it usually arrives with none of these. That is where email matching comes in: when a Stripe payment has no visitor ID, Virling compares its payer email (billing details or receipt email) with the emails your visitors shared in identify events. If one matches, the payment is credited to that visitor and shows Matched by email on the Payments page.

Virling finds the invoice a charge paid through Stripe's Invoice Payments. If the invoice's billing reason is subscription_cycle, the charge is a renewal and takes the attribution of the customer's first payment, matched by Stripe customer ID, even years later. Upgrades and plan changes (subscription_update) keep the first payment's channel too. So getting the first invoice attributed carries the whole subscription with it.

Which visit gets the credit

Each site has one attribution model and one lookback window, set in site settings. Only sessions that started inside the window before the payment count. The window is 90 days by default, and can be 30, 60, 90 or 365 days. Pick one longer than your usual sales cycle; how long a visitor takes to become a customer shows how to measure it.

  • Last non-direct, the default: the latest session in the window that was not Direct
  • First touch: the earliest session in the window, the channel that introduced the buyer
  • Last touch: the latest session in the window, Direct included

First touch fits longer buying cycles, where the buyer often comes back by typing your URL before the call. See first touch vs last touch attribution for SaaS for the trade-offs. Changing the model rebuilds attribution for every past payment of the site.

An example: three invoices paid weeks later

Example data, made up to show the method: an imaginary contract review tool uses First touch with the default 90-day window and sends an identify event with the email from its demo form. It sends each buyer a Stripe invoice after the call, so none of the payments carries a visitor ID, and each is joined to its visitor by the payer email.

InvoiceFirst visit sourceFirst visitDemo bookedPaidDays to payAmount
AOrganic search, google.comSep 2Sep 9Oct 1442$4,650
BCommunities, news.ycombinator.comSep 15Sep 18Oct 621$2,350
CSocial, linkedin.comAug 20Sep 24Nov 375$7,900
All threemedian 42$14,900

For invoice A, the buyer typed their work email into the demo form on Sep 9, so Virling kept a hash of that email for their visitor. When the invoice was paid on Oct 14 from the same address, Virling matched the payer email to that visitor, shown as Matched by email, and credited the earliest session in the window, the Google search on Sep 2. B and C were joined the same way. C took 75 days, so it fits the 90-day window, but under a 60-day window its LinkedIn visit would fall outside, and the credit would move to a later session such as the Sep 24 visit when the demo was booked. Measure your own days to close with the sales cycle calculator before you pick a window.

Making sales-led deals attributable

The goal is to capture the visitor ID or the buyer's email while they are still on your site, before the deal moves to calls and email. If the booking form is a calendar embedded from another site, see how to track revenue from demo bookings.

At signup or demo booking, send the email. When someone signs up or fills in a demo form on your own page, send an identify event with their email. Virling keeps only a salted SHA-256 hash of the trimmed, lowercased email. A later Stripe payment with no visitor ID whose payer email matches is credited to that visitor:

await fetch("https://app.virling.com/api/event", {
  method: "POST",
  headers: { "user-agent": req.headers["user-agent"] },
  body: JSON.stringify({
    n: "identify",
    u: "https://yourdomain.com/book-a-demo",
    s: "yourdomain.com",
    v: req.cookies.virling_vid,
    m: form.email,
  }),
});

This works from the browser too, with window.virling?.vid?.() as v. The full recipe is in Unattributed revenue in the docs.

When the buyer pays through your own checkout, send the visitor ID. If the deal closes with a Checkout Session or a PaymentIntent your server creates, pass the virling_vid cookie as client_reference_id or metadata.virling_vid. The code for each provider is in Link checkout to visits. If signup or the app lives on another domain, carry the ID across first: see cross-domain checkout attribution.

What stays unattributed, and why

Unattributed payments still count toward revenue; they are just not credited to a visit. For invoiced deals the usual reasons are:

  • A different payer. Email matching is exact. If the person who booked the demo is not the person whose email is on the payment, such as an accounts team, nothing matches.
  • No identify before the payment. Email matching applies to payments synced after the identify event, so send it at signup or booking, not after the invoice is paid.
  • No session in the window. The visitor is known but all their sessions started before the lookback window.
  • The visit was never tracked. The script was blocked by an ad blocker, the visitor had Global Privacy Control with data-respect-gpc, the visit was filtered as a bot, or the site runs in cookieless mode, where there is no visitor ID.
  • Deals that never touched the site. A buyer met at an event or through a referral who books by email has no visit to credit.
  • Old subscriptions. Payments older than the 90-day backfill are not imported, so renewals of subscriptions that started before then have no first payment to copy from.

Keep Unattributed as its own line rather than spreading it across channels. A growing share is a sign that a form or checkout stopped sending the ID or email.

Doing it with Virling

Connect Stripe with a restricted key that can only read, add the script to your site, and send an identify event from your signup or demo form. Virling imports charges, finds their invoices, marks renewals and credits each payment to a channel. The setup for software companies is on the SaaS integration page, and the key steps are on the Stripe integration page.

Frequently asked questions

Can a Stripe invoice be attributed to a marketing channel?

Yes, if Virling can tie it to a visitor. A payment that carries a visitor ID is matched directly. An invoice with no visitor ID is credited to a visitor when its payer email matches an email that visitor shared earlier in an identify event.

Does the invoice need to be paid on the same day as the visit?

No. Virling considers every session of that visitor that started inside the lookback window before the payment. The window is 90 days by default and can be set to 30, 60, 90 or 365 days.

Are renewals of an invoiced subscription credited too?

Yes. A Stripe charge whose invoice has billing reason subscription_cycle is a renewal and takes the attribution of the customer's first payment, matched by Stripe customer ID. If that first payment was Unattributed, the renewal usually is too.

Why is an invoice still Unattributed after I sent an identify event?

The payer email on the charge must match the identified email exactly after trimming and lowercasing, the identify must happen before the payment is synced, and the visitor needs a session inside the lookback window. An invoice paid by a different person, such as an accounts team, does not match.

Does Virling store the buyer's email?

No. It keeps only a SHA-256 hash of the trimmed, lowercased email, salted per site, and matching never crosses sites.

See which channels bring your invoiced deals

Virling is open source under AGPL. Self-host it free, or use the hosted version with a 14-day free trial. It connects to Stripe, Paddle, Shopify, WooCommerce, Polar, LemonSqueezy, Dodo, Creem and RevenueCat.

Start free trial See the demo