virling Pricing Self-host Demo Changelog Agencies GitHub Start free trial
tools / attribution setup generator

Revenue attribution setup generator

This generator writes a setup checklist for SaaS founders, store owners and developers who want to see which channel brought each payment. Pick your site builder and payment provider, and it lists the steps for that pair in order: add the script, connect a payment key, pass the visitor ID into checkout, and make a test payment. Each step links to its docs, and you can copy the whole list as text. Everything runs in your browser.

Site builder or framework
Payment provider

    See which channel brought each payment

    Once the checklist is done, Virling credits each payment to the visit that led to it, and shows revenue for every channel, referrer and page. Virling is open source under AGPLv3: self-host it free, or start a 14-day hosted trial.

    Start free trial Checkout snippet generator · See the demo

    What to do with the steps

    Work through the checklist from top to bottom. You need a Virling site first: start a free trial, or follow the quickstart to run Virling on your own server.

    1. Add the Virling script. Use the tag from your own setup screen, since it holds your Virling server in src and your domain in data-site. It belongs on every page, not only the checkout page, because the first page a visitor opens is where the source is recorded. Pages on subdomains of data-site count toward the same site.
    2. Connect your payment provider. Create the key with the permissions in the step and paste it in Virling. The first sync imports the last 90 days, or 60 for Shopify. After that, Virling checks for new payments every minute and converts amounts to USD for reports. RevenueCat is different: the first sync imports one-time purchases only, and new purchases arrive by webhook.
    3. Pass the visitor ID into checkout. This is the step that links a payment to a visit. On your server, read the virling_vid cookie from the request that creates the checkout. In the browser, call window.virling?.vid?.() and check that it returned a value, since the script may be blocked by an ad blocker or not loaded yet. The checkout snippet generator has the code for each provider.
    4. Check the webhook. This step appears only for LemonSqueezy, Creem and RevenueCat. Virling adds the webhook when you connect, so there is nothing to create. If you self-host, confirm that your Virling server is on a public https address.
    5. Make a test payment. Open your site in a private window from a tagged link, go to checkout from there, and pay. After the next sync, the payment should show a channel instead of Unattributed. Test your setup covers test mode for each provider.

    If the test payment is Unattributed, go back to step 3 before changing anything else. The attribution audit checklist checks each part of the path in turn.

    A worked example: SaaS on Stripe

    Example: a subscription product built with Next.js creates Stripe Checkout Sessions on its server. Its founder picks Next.js and Stripe, and the generator returns:

    1. Add the Virling script to your Next.js site. Add your site in Virling and copy the tag from its setup screen. Load it once with next/script and strategy="afterInteractive", in app/layout.tsx (App Router) or pages/_app.tsx (Pages Router). Leave out defer. Then open the site: the setup screen updates when the first pageview arrives.
      Next.js setup docs · Next.js guide
    2. Connect Stripe to Virling. In the Stripe Dashboard, open Developers, API keys, Create restricted key, and set Read on Charges, Checkout Sessions, Customers, Events, Invoices, Subscriptions and PaymentIntents. The key starts with rk_live_; secret keys are refused. In Virling, open your site, Setup, Connect payments, pick Stripe, paste the key and click Connect and backfill.
      Stripe docs · Stripe guide
    3. Pass the visitor ID into Stripe checkout. Payment Links on buy.stripe.com need no code: the script adds client_reference_id on click. For a Checkout Session you create, set client_reference_id (or metadata.virling_vid) to the visitor ID; for your own PaymentIntent, set metadata.virling_vid. In a route handler, read req.cookies.get("virling_vid")?.value; in a server action, (await cookies()).get("virling_vid")?.value from next/headers. The checkout snippet generator has the code.
      Link checkout to visits · Stripe checkout docs
    4. Make a test payment. Pay 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.
      Check that it works · Unattributed payments

    This product uses no Payment Links, so the part of step 3 that applies is the Checkout Session: the route handler that creates it reads the cookie and sets it as client_reference_id. If that field already holds something else, use the session's metadata.virling_vid instead. Renewals need no extra code, since each one keeps the channel of the customer's first payment, as long as that payment is in Virling.

    A worked example: WooCommerce store

    Example: a store runs WooCommerce on its WordPress site. Its owner picks WordPress and WooCommerce, and the generator returns:

    1. Add the Virling script to your WordPress site. Add your site in Virling and copy the tag from its setup screen. Install the Virling plugin: upload the integrations/wordpress/virling folder from the repository to wp-content/plugins/, activate it, and enter your Virling server and site domain in Settings, Virling. Without the plugin, paste the tag before </head> in header.php. Then open the site: the setup screen updates when the first pageview arrives.
      WordPress setup docs · WordPress guide
    2. Connect WooCommerce to Virling. In WordPress, open WooCommerce, Settings, Advanced, REST API, and add a key with Read permission. Paste the consumer key and secret as ck_...:cs_... and your store address. The store must answer over https with pretty permalinks on. In Virling, open your site, Setup, Connect payments, pick WooCommerce, paste the key and click Connect and backfill.
      WooCommerce docs · WooCommerce guide
    3. Pass the visitor ID into WooCommerce checkout. Add the order snippet to your theme's functions.php, or a snippets plugin. It copies the visitor ID from the cookie onto every new order, in the classic and the block checkout. The checkout snippet generator has the code.
      Link checkout to visits · WooCommerce checkout docs
    4. Make a test payment. Pay 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.
      Check that it works · Unattributed payments

    No checkout template changes are needed: the snippet in step 3 saves the visitor ID on each new order. For step 4, put the payment gateway in test mode, or use Cash on delivery and set the order to Processing, which counts as paid. Then check that the order's custom fields include virling_vid.

    How revenue attribution works

    1. The Virling script stores a visitor ID in the first-party virling_vid cookie and records each visit with its referrer and UTM tags.
    2. Virling reads payments from your provider with a read-only key, polling once a minute.
    3. When checkout carries the visitor ID, the payment is joined to the visits behind it. Payments without it still count toward revenue, as Unattributed.

    Hosted checkout links on buy.stripe.com, buy.polar.sh, checkout.dodopayments.com and *.lemonsqueezy.com need no code: the script adds the visitor ID to them. The full reference is in link checkout to visits.

    Guides on tracking revenue by source

    questions

    Attribution setup FAQ

    How do I track revenue by traffic source?

    Add the Virling script to your site, connect your payment provider with a read-only key, and pass the visitor ID from the virling_vid cookie into checkout. Virling then joins each payment to the visit that led to it, with its referrer and UTM tags.

    Do I need a backend?

    Not always. Hosted checkout links on buy.stripe.com, buy.polar.sh, checkout.dodopayments.com and *.lemonsqueezy.com need no code, and Paddle.js can read the ID in the browser. Checkouts you create with a secret API key, such as Creem checkouts, need a server.

    Does Virling change anything in my payment account?

    It never creates, changes or refunds a payment. Use a key with only the permissions listed in the step. LemonSqueezy keys cannot be made read-only, and Creem and RevenueCat keys need webhook access, because Virling adds a webhook on those three when you connect.

    What happens to payments without the visitor ID?

    They still count toward revenue, as Unattributed, but are not credited to any visit or channel. That includes most payments from before the script was on your site, so set up the script and checkout before you judge a channel.

    Does it work when my app or checkout is on another domain?

    Yes, if the payment carries the visitor ID. Subdomains such as app.yourdomain.com share the virling_vid cookie. If checkout starts on a second domain you own, pass the visitor ID along in the link and on to checkout, and add that domain under Same-visit domains in Site settings.

    How do I check that the setup works?

    Open your site in a private window from a link with UTM tags, pay in your provider's test mode, and wait a minute for the next sync. The payment should show the source of your tagged visit instead of Unattributed. Payments imported with a test key stay in your reports, so for real payments only, make one small live payment and refund it.

    See which channel brought each payment

    Virling links every payment to the visit it came from, so you see the post, search or AI answer behind your revenue. 14 days free.

    Start free trial See the demo