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

How to track Creem revenue by traffic source

By Devendra Variya, co-founder of Virling. Published 2026-11-16, updated 2026-12-01.

To track Creem revenue by traffic source, give each visitor an ID, put it in the checkout's metadata, catch it in a webhook, and join each payment back to the visits that came before it. Creem knows who paid and how much. It does not know which page or channel they came from, and unlike most providers it only hands the metadata back in a webhook.

Step 1: set a visitor ID

Your analytics script sets one first-party ID per visitor and remembers the first source: referrer, UTM tags or direct. Put the script on the pages that link to checkout, not only on the checkout itself. With Virling the ID lives in the virling_vid cookie on your own domain, so your backend receives it with every request from the browser. The UTM tags stay with the visit, not the Creem checkout; Creem UTM tracking shows how the ID ties each payment back to them.

If you read it in the browser instead, window.virling?.vid?.() returns the same ID. It returns nothing when the script is blocked or has not loaded yet, and null in cookieless mode, so check the value before you use it. The script loads with defer, so code that runs early should wait for it.

Step 2: send the ID to Creem at checkout

Creem checkouts carry metadata, so the ID can travel with the purchase. When your server creates the checkout, read the cookie from the request and set it in metadata:

const res = await fetch("https://api.creem.io/v1/checkouts", {
  method: "POST",
  headers: { "x-api-key": process.env.CREEM_API_KEY, "content-type": "application/json" },
  body: JSON.stringify({
    product_id: "prod_...",
    success_url: "https://yourdomain.com/thanks",
    metadata: { virling_vid: req.cookies.virling_vid },
  }),
});
// Send the customer to (await res.json()).checkout_url

Use https://test-api.creem.io with a test mode key. The customer then pays on Creem's page, and the metadata stays attached to that checkout.

Step 3: catch the metadata in a webhook

This is where Creem differs. Creem returns checkout metadata only in webhooks, not on transactions. Reading transactions from the API tells you what was paid, but not which visitor paid it. So you need a webhook for checkout.completed that stores the visitor ID next to the checkout, and you need to verify each delivery: Creem signs the body with HMAC-SHA256 and sends the result in the creem-signature header.

A webhook needs an https address that Creem can reach. If your analytics run on a server only reachable over plain http, payments can still be imported, but nothing links them to a visit, so they stay Unattributed.

Virling adds this webhook when you connect Creem, and its Payments page shows each Creem payment with the source it was credited to, or as Unattributed.

Start free trial See the demo

Step 4: read payments and join them to visits

Read transactions from the Creem API with a scoped key and look for the visitor ID in a fixed order: the checkout's metadata from the webhook, then the subscription's metadata, then the customer's metadata. Match each ID to that visitor's earlier visits and credit one of them with a rule you keep fixed (see first touch or last touch). Payments with no ID have no visit to join, so they show as Unattributed. They still count toward revenue, which keeps your totals honest.

Step 5: handle refunds, renewals and trials

A refund or chargeback can land weeks after the payment. Read recent transactions again on a schedule so later refunds update them, or a channel will look better than it is.

Subscriptions bring the same customer back every month. Treat every payment after a customer's first as a renewal that keeps the channel of the first payment, so renewals are not mistaken for new customers from Direct. See renewals in the docs. For a subscription business, Creem SaaS attribution shows how the Creem customer ID carries the first channel to each renewal.

Free trials need one more rule. A completed checkout with nothing to pay starts a trial, and the customer's first paid transaction should be credited to the visit behind that trial, not to whatever they did on the day the card was charged.

A worked example: three Creem payments

Example data, made up to show the method. An imaginary SaaS sells a $74 monthly plan and a $163 lifetime plan through Creem, with the default model, last non-direct. The visitor IDs are sample values. To get the same setup on your own stack, the attribution setup generator lists the steps for your site builder and Creem.

PaymentVisitor ID set on the pageMetadata on the paymentCredited to
1. Monthly plan, $74, day 1k7f2q9xd, set on a visit from a Google search; the visitor came back by typing the URL and paid{"virling_vid": "k7f2q9xd"} in the checkout.completed webhookOrganic search, new customer
2. Monthly plan, $74, day 31None: Creem charged the card, there was no visitNo checkout and no webhook; the transaction has the same Creem customer as payment 1Organic search, renewal
3. Lifetime plan, $163, day 9, refunded day 16m3p8w1zt, set on a visit from a newsletter link tagged utm_medium=email{"virling_vid": "m3p8w1zt"} in the checkout.completed webhookEmail, refunded

The three payments add up to $311 before refunds. Payment 1 goes to Organic search, not Direct, because the typed visit is skipped for the Google search before it. Payment 2 has no metadata of its own, but it is the same customer's second payment, so it is a renewal and keeps Organic search: $148 from one customer. Payment 3 is credited to Email on day 9, and when the transaction is read again after the refund it counts as refunded, so Email ends with one refund and $0 net instead of $163. Net revenue is $148, all from Organic search.

Step 6: report revenue per channel

Group the joined payments by channel and divide by visitors to get revenue per visitor. That is the table that tells you where to spend time. Trial to paid by channel is worth a look too, since a channel can bring many trials and few payments (see trial to paid conversion by traffic source).

Checkout on another domain or a second site? See cross-domain checkout attribution.

What goes wrong

  • Creating the checkout without metadata, so payments import with no visitor and fall into Unattributed
  • Reading only transactions from the API and never the webhook, so the metadata is never seen
  • Running analytics on plain http, so Creem cannot deliver the webhook
  • Skipping the signature check on the webhook, so anyone can post fake checkouts
  • Reading the visitor ID in the browser before the script has loaded, so it is empty
  • Giving the key more scopes than it needs
  • Ignoring refunds and chargebacks, which overstates a channel

Doing it with Virling

Virling reads Creem transactions and, when allowed, subscriptions with a scoped API key. In Creem, open Developers, then API keys, and create a key with the transactions:read scope, plus subscriptions:read so Retention can tell who still pays, and webhooks:write so Virling can add its webhook. No other scopes are needed. Paste it into Virling. Live and test mode keys both work: Virling tries api.creem.io first and test-api.creem.io second, or the other way round for a key that starts with creem_test_.

When you connect, Virling adds one webhook for checkout.completed that points at https://<your Virling>/api/webhooks/creem/<site ID>, keeps its signing secret encrypted, and checks each delivery against the creem-signature header. You do not write a webhook handler yourself.

It imports transactions from the last 90 days on the first run, then new ones every minute. Transactions from the last 60 days are read again every 6 hours, so later refunds and chargebacks update them. Subscription status is read once an hour when the key has subscriptions:read; without it, retention falls back to payment recency. Renewals and free trials are handled as described above.

The only code on your side is the metadata line in Step 2. The setup is in the docs and on the Creem integration page.

Frequently asked questions

Can Creem show which traffic source a sale came from?

Not on its own. Creem records the transaction, not the visit. You need to put a visitor ID into the checkout's metadata and join it to your analytics.

Why does Creem attribution need a webhook?

Creem returns checkout metadata only in webhooks, not on transactions. Virling adds one checkout.completed webhook when you connect, so it needs to be reachable over https.

Which channel do Creem renewals get?

Every payment after a customer's first is a renewal and keeps the channel of the first payment, so it is not counted as a new customer from Direct.

Which Creem API key scopes are needed?

transactions:read, plus subscriptions:read for Retention and webhooks:write so Virling can add its webhook. No other scopes are needed.

See your Creem revenue by traffic source

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