Attribute revenue to visitors

Attribution is what connects a payment to the visit that caused it. With it, a sale in Payments shows the source, campaign or referrer that brought the customer in, and Revenue by source, Customers and Cohorts can tell you which marketing actually pays for itself.

SnowAnalytics links a customer in your payment provider to a SnowAnalytics visitor. The reliable way is to pass the visitor id yourself, which you wire up once. With Stripe you have two methods, below: pass the id at checkout, or send it to SnowAnalytics from your server. Polar, Dodo Payments, RevenueCat and Superwall each take it in their own place; see where each provider reads the visitor id. Either way it's the visitor id the SnowAnalytics tracker assigns, and SnowAnalytics uses it to tie the resulting payments back to the right visit. SnowAnalytics also checks a few other signals on its own.

For every payment, SnowAnalytics looks for a visitor with the first of these that applies:

  1. Visitor id on the payment: an sa_visitor_id in the metadata of a Stripe Checkout Session (for one-time payments) or of the subscription (for subscription payments), or the equivalent for another provider. This is the method set up below.
  2. Customer linked earlier: an earlier checkout, subscription or purchase for the same customer carried sa_visitor_id. All of that customer's payments then link to that visitor.
  3. Stripe customer id from Identify: you sent a stripe_customer_id with the Identify API. This one is for Stripe only.
  4. Same email: the payment's email matches an email you sent with Identify for a signed-in user. This works for every provider, as long as the payment carries the customer's email.

The payment then takes the source of that visitor's first visit. A payment that matches none of these shows as Not linked to a visit, and Revenue by source tells you what share of your revenue SnowAnalytics matched.

SnowAnalytics only matches data you already send it: the visitor id, your identify calls and the customer details from your provider. If your site only tracks visitors who consent, only those visitors can be linked.

Get the visitor id

On the client, the tracker exposes the current visitor's id:

const visitorId = window.sa.getVisitorId();

It returns an empty string in cookie-free mode, and for visitors who opted out or send Do Not Track or Global Privacy Control.

You'll pass this id along when you create the checkout, or send it to the Identify API from your server. The tracker also has window.sa.getSessionId(). Every provider below reads an optional sa_session_id the same way, but the visitor id is what links a payment.

Where each provider reads the visitor id

Put the visitor id where your provider's events carry it:

ProviderWhere SnowAnalytics reads sa_visitor_idThe email SnowAnalytics matches on
StripeThe metadata of the Checkout Session, and of the subscription for subscription payments, or a Payment Link's client_reference_idThe customer's email on the invoice or session
PolarThe metadata of the checkout, which Polar copies onto the order and subscription, or a Checkout Link's reference_id as <visitorId>.<sessionId>The customer's email on the order
Dodo PaymentsThe metadata of the checkout session or paymentThe customer's email on the payment
RevenueCatThe sa_visitor_id subscriber attributeThe $email subscriber attribute
SuperwallThe sa_visitor_id user attributeThe email user attribute

Each connect page has the code for its provider. The Stripe code is below.

Choose a method

These two methods are for Stripe.

When you create the Stripe Checkout Session, read the visitor id from window.sa.getVisitorId() and pass it into the session's metadata under the key sa_visitor_id. For subscriptions, also put it in the subscription's own metadata: Stripe copies that onto each invoice, which is where SnowAnalytics reads it.

const visitorId = window.sa.getVisitorId();

// Send the visitor id to your server, which creates the Checkout Session.
await fetch("/create-checkout-session", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ visitorId }),
});

Then, on your server, include it when you create the session:

const session = await stripe.checkout.sessions.create({
  mode: "subscription", // or "payment"
  line_items: [{ price: "price_123", quantity: 1 }],
  success_url: "https://example.com/success",
  cancel_url: "https://example.com/cancel",

  // Links the Stripe customer and one-time payments to the SnowAnalytics visitor:
  metadata: { sa_visitor_id: visitorId },

  // For subscriptions, also stamp it on the subscription itself. SnowAnalytics reads
  // it there for every renewal, so a subscription created without Checkout
  // still links:
  subscription_data: {
    metadata: { sa_visitor_id: visitorId },
  },
});

Stripe Payment Links take no metadata. Add the visitor id to the link's URL as client_reference_id instead, and SnowAnalytics reads it from the completed checkout:

const link = "https://buy.stripe.com/test_abc123";
const visitorId = window.sa.getVisitorId();
location.href = visitorId
  ? `${link}?client_reference_id=${encodeURIComponent(visitorId)}`
  : link;

SnowAnalytics only takes a client_reference_id that is a visitor id it has seen on your site, so a link that already passes your own user id there keeps working.

SnowAnalytics does not inject sa_visitor_id for you. You add it yourself when you create the Checkout Session. That's the step that makes attribution work.

Requirements and limits

Linking a payment to the original visit needs a visitor id that stays the same across visits. That means Cookie mode. Choose it under Site settings → Installation → Privacy, then replace the snippet on your website with the new one, which carries data-mode="attribution". New sites start Cookie-free, unless you turned on revenue during setup.

In Cookie-free mode the visitor id changes every day and lives only on SnowAnalytics' server, so there's no stable id to hand to your provider. Linking a payment to the visit that started it isn't available. If that matters to you, switch the site to Cookie mode and replace the snippet already deployed on your website.

See it land

Once attribution is wired up, new payments show their source in Payments, and the customers behind them show up under Revenue by source and Customers. The visitors you linked also show their customer status and revenue on Visitors. For more on identifying visitors generally, see Identify users.

On this page