How to track Dodo Payments revenue by traffic source
By Devendra Variya, co-founder of Virling. Published 2026-11-16, updated 2026-12-01.
To track Dodo Payments revenue by traffic source, give each visitor an ID, put it in the payment's metadata at checkout, and join each payment back to the visits that came before it. Dodo Payments knows who paid, for which product and how much. It does not know which post, search or ad sent that customer to your site.
This guide walks through the whole join by hand, then shows how Virling does it for you. Either way, the hard part is the same: the visitor ID has to reach Dodo before the customer pays.
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 every page that links to checkout, not only on your landing page. A payment that starts on a page without the script cannot be traced.
The ID should live in a first-party cookie on your own domain, so your server receives it with every request from the browser and can pass it on when it creates a checkout.
Step 2: send the ID to Dodo at checkout
Dodo payments carry metadata, so the ID can travel with the payment. Pick the option that matches how you sell:
- Static payment links on
checkout.dodopayments.com/buy/...: add the ID to the link asmetadata_virling_vid, and Dodo stores it as the payment'smetadata.virling_vid - Checkout sessions you create on your server: set
metadatato an object holding the ID from the visitor's cookie
A checkout session created with the Dodo Payments Node SDK looks like this:
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: "pdt_...", quantity: 1 }],
return_url: "https://yourdomain.com/thanks",
metadata: { virling_vid: req.cookies.virling_vid },
});
// Send the customer to session.checkout_urlIf you build a payment link URL in your own code instead of using a plain link, add the parameter yourself, and only when there is a value:
const url = new URL("https://checkout.dodopayments.com/buy/pdt_...");
const vid = window.virling?.vid?.();
if (vid) url.searchParams.set("metadata_virling_vid", vid);
location.href = url.href;If that code can run before the analytics script has loaded, the value will be empty, so wait for the script first.
Step 3: read the ID back from the payment
Create an API key in the Dodo Payments dashboard and list payments from the Dodo API. Live and test mode use different hosts, live.dodopayments.com and test.dodopayments.com, so make sure you read from the one your key belongs to. The visitor ID sits in the payment's metadata.virling_vid.
Payments can succeed some time after they are created, so a single pass over yesterday's list will miss some. Re-read a recent window on every run instead of only asking for what is new. Keep an eye on Dodo's rate limit of 240 requests per minute while you backfill.
Step 4: join payments to visits
Match each payment's 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; you just cannot say where they came from.
Virling does this join for Dodo Payments, and its Channels card puts each channel's visitors next to the revenue and revenue per visitor they brought.
Step 5: handle refunds, disputes and renewals
A refund does not change when a payment was made. Read refunds on their own and apply each one to the payment it belongs to, or a channel will look better than it is. Treat a lost or accepted dispute the same way, since the money went back to the customer.
Subscriptions need one more rule. A subscription produces a payment every billing period, and only the first paid one is a new customer. Mark every later paid payment as a renewal, so a channel is not credited with a new sale each month. Counting from the first paid payment, not the first payment, means the first charge after a free trial is still the first payment. Attribution for SaaS on Dodo Payments applies these rules to plans with usage billing and add-ons.
Step 6: filter to your products
One Dodo account can sell more than one product, and not all of them belong to the site you are measuring. Keep a list of the product IDs that belong to this site and drop the rest. A subscription payment belongs to its subscription's product.
Step 7: 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.
A worked example: gross and net by channel
Example data, made up to show the method. An imaginary product sells one $71 plan through Dodo Payments. The table shows a sample month: the paid payments credited to each of four channels, the refunds and lost disputes later applied to those payments, and what is left. To set up the visitor ID for your own site builder and Dodo, use the attribution setup generator.
| Channel | Dodo payments | Gross revenue | Refunds | Lost disputes | Net revenue |
|---|---|---|---|---|---|
| Organic search | 21 | $1,491 | 1 ($71) | 0 | $1,420 |
| Paid | 11 | $781 | 3 ($213) | 1 ($71) | $497 |
| 9 | $639 | 0 | 0 | $639 | |
| AI | 5 | $355 | 1 ($71) | 0 | $284 |
| Total | 46 | $3,266 | 5 ($355) | 1 ($71) | $2,840 |
By gross revenue, Paid is the second channel, $142 ahead of Email. By net revenue it falls behind Email, because 4 of its 11 payments went back to the customer: three refunds and a dispute the seller lost, 36% of its gross. Organic search lost 5%, AI 20% and Email nothing. Since refunds and disputes are applied to the payment they belong to, a refund that lands next month still lowers this month's Paid figure. A dispute that is still open does not count until it is lost or accepted.
Checkout on another domain or a second site? See cross-domain checkout attribution.
What goes wrong
- Creating the checkout session without metadata, so payments import with no visitor and fall into Unattributed
- Building the payment link before the script has loaded, so the ID is empty
- Pointing a test key at the live host, or the other way round, so nothing comes back
- Reading only new payments, so ones that succeed late are missed
- Ignoring refunds and disputes, which overstates a channel
- Counting every subscription payment as a new sale
Doing it with Virling
Virling reads Dodo Payments payments, refunds and subscriptions with an API key. Create the key in the Dodo Payments dashboard and paste it into Virling. Live mode and test mode keys both work: Virling tries the key against live.dodopayments.com first and test.dodopayments.com second, and remembers which one accepted it.
It imports payments from the last 90 days on the first run, then new ones every minute. Listing walks one day at a time and re-reads the last 30 minutes on each round, so payments that succeed late are not missed. Refunds update the payment they belong to, and lost or accepted disputes count as refunded. For a subscription payment, Virling looks up the subscription's paid payments and marks every one after the first paid one as a renewal. To stay inside Dodo's rate limit it makes at most a couple of extra lookups per round, so a large backfill can take a few minutes to finish.
If one Dodo account sells more than this site's products, list the site's product IDs in site settings, under Payment connections, in Only these product IDs. Virling then imports only payments, refunds and subscriptions for those products.
Static payment links on checkout.dodopayments.com/buy/... need no code. Keep the link as a normal <a href> on a page that runs the script, and the script adds metadata_virling_vid with the visitor ID unless it is already there. For checkout sessions you create yourself, set virling_vid in metadata from the virling_vid cookie, as in step 2. To check it works, make a test payment from a page that runs the script, wait for the next sync, and open the payments list: the payment should show a channel instead of Unattributed. The setup is in the docs and on the Dodo Payments integration page.
Frequently asked questions
Can Dodo Payments show which traffic source a sale came from?
Not on its own. Dodo Payments records the payment, not the visit. You need to put a visitor ID into the payment's metadata and join it to your analytics.
Do Dodo payment links need code to carry the visitor ID?
No. A static payment link on checkout.dodopayments.com can take the visitor ID as a metadata_virling_vid query parameter, which Dodo stores as the payment's metadata.virling_vid. The Virling script adds it for you.
How are Dodo subscription renewals counted?
Every paid payment of a subscription after the first paid one is marked as a renewal, so renewals are not counted as new customers. The first charge after a free trial counts as the first payment.
Do test mode keys work?
Yes. Virling tries the key against live.dodopayments.com first and test.dodopayments.com second, and remembers which one accepted it.
See your Dodo Payments 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.