WordPress revenue tracking: which channel brought each sale
By Devendra Variya, co-founder of Virling. Published 2026-11-19, updated 2026-11-29.
To see which channel brought each WordPress sale, every payment needs an ID that points back to the visit. Add the Virling script to your site with the Virling plugin or in your theme's header, and it records the referrer and UTM tags of every visit against a visitor ID. Then make the payment carry that ID: for WooCommerce, a short snippet stores it on each order; for Stripe Payment Links and other hosted checkout links, the script adds it to the link by itself. Connect your store or provider, and each sale shows the channel that brought it.
Why WordPress sales lose their source
A visitor lands on your WordPress site from a search, a post or an ad, then buys. The visit and its source are known on the page; the payment is recorded somewhere else, in a WooCommerce order or on a hosted checkout page such as buy.stripe.com. Your analytics see the visit but not the payment, and the store or provider sees the payment but not where the visit came from. What joins the two is one ID that the payment keeps and hands back. Virling uses the visitor ID in the first-party virling_vid cookie, and there are two ways to get it onto a WordPress sale, depending on how you sell.
Step 1: add the script to WordPress
With the Virling plugin. Download the integrations/wordpress/virling folder from the repository, upload it to wp-content/plugins/ and activate it. Under Settings, Virling, enter your Virling server and your site domain. The plugin adds the tag to every page, survives theme updates and skips logged-in administrators by default.
In your theme. Open Appearance, Theme File Editor, open header.php and paste the tag before </head>. A plugin that adds code to the site header works too, as long as it keeps the tag's attributes. The app shows the exact tag for your site:
<script defer src="https://app.virling.com/v.js" data-site="yourdomain.com"></script>
The script reads data-site from its own tag, so it must stay on the tag. Every option is in the framework setup docs.
Step 2a: WooCommerce orders
WooCommerce checkout runs on your own site, so the order can keep the visitor ID directly. Add this to your theme's functions.php, or to a snippets plugin, so every new order stores the ID from the virling_vid cookie. It covers the classic and the block checkout:
add_action('woocommerce_checkout_create_order', 'virling_vid_on_order');
add_action('woocommerce_store_api_checkout_update_order_from_request', 'virling_vid_on_order');
function virling_vid_on_order($order) {
$vid = $_COOKIE['virling_vid'] ?? '';
if (preg_match('/^[A-Za-z0-9-]{8,64}$/', $vid)) $order->update_meta_data('virling_vid', $vid);
}Then connect the store. In WordPress, open WooCommerce, Settings, Advanced, REST API, add a key and set Permissions to Read. In Virling, paste the consumer key and secret joined by a colon, as ck_...:cs_..., with your store's address. The store must be reachable over https, with pretty permalinks on.
Virling imports orders from the last 90 days on the first run, then new ones every minute. Processing and completed orders count as paid, and refunds lower each order's revenue. With WooCommerce Subscriptions, a renewal keeps the channel of the first payment. The full setup is on the WooCommerce integration page, a walkthrough is in how to track WooCommerce revenue by traffic source, and what the built-in order attribution shows is in WooCommerce UTM tracking.
Step 2b: Stripe payment links or a hosted checkout
If your WordPress buttons link to a hosted checkout, nothing else goes on the page. Set the button's link to the checkout URL from your provider, such as https://buy.stripe.com/abc123. The script adds the visitor ID to every such link when the page loads and again on click, and never replaces a parameter that is already there:
- Stripe:
buy.stripe.comlinks getclient_reference_id, read from the Checkout Session. - Polar:
buy.polar.shlinks getreference_id, read from the order's metadata. - Dodo Payments:
checkout.dodopayments.comlinks getmetadata_virling_vid, read from the payment's metadata. - LemonSqueezy:
lemonsqueezy.comcheckout links getcheckout[custom][virling_vid], read from the webhook's custom data.
The link must be a normal link on a page that runs the script. If your own code creates a Stripe Checkout Session on the server instead, pass the virling_vid cookie as client_reference_id; the checkout docs show it for each provider. Then, in Virling, add the provider under Payment connections in site settings: Stripe takes a restricted key with Read access. What a Payment Link keeps and drops is in Stripe Payment Link UTM tracking.
Ways to take payments on WordPress, and what can be linked
A WordPress site can take payments in several ways, and some need one more setting than others:
| How you take payments | Can the visitor be linked? | Needs a setting | Not supported |
|---|---|---|---|
| Payment Link or other hosted checkout link on a Buttons block or in text | Yes, for links on buy.stripe.com, buy.polar.sh, checkout.dodopayments.com and lemonsqueezy.com | The script on the page, from the plugin or the theme | Links on a custom checkout domain, and links opened outside your site |
| WooCommerce classic or block checkout | Yes, through virling_ on the order | The snippet above in functions.php or a snippets plugin, and a Read key | Orders added by hand in the dashboard, and orders from before the snippet, unless you match by email |
| WooCommerce express checkout buttons on product, cart and checkout pages | Only if the button creates its order through the classic or block checkout | The same snippet. Place a test order with each button and look for virling_ | Buttons that create the order outside those two |
| Stripe Checkout Session created by your own code | Yes | The virling_ cookie passed as client_ | Sessions created without it |
| Stripe Buy Button pasted as HTML | Not by itself. It is not a plain link, so the script does not tag it | Your own code that sets its client-reference-id from window.virling.vid(), or the Payment Link on a normal button | The channel, when neither is done. The payment still counts if you connect the same Stripe account |
| Payment Buttons block on WordPress.com | Not by visitor ID. It is not a link on the hosts above | None in the block | Linking by visitor ID. Charges in the Stripe account you connect count as Unattributed, unless you match by email |
On WordPress.com, plugins need a paid plan. The no-code setup for other site builders, with the same checkout hosts, is in the no-code guide. On Wix, the tag goes in Custom Code instead of a plugin: see how to track Wix sales by channel.
Step 3: make a test payment
- Log out of WordPress or use a private window, since the plugin skips administrators.
- In that window, open
https://yourdomain.com/?utm_source=test&utm_medium=test, with your own domain. - In another window, open your Virling dashboard. The visit shows under Visitors right away, and
testshows on the Channels card. If it is missing, check the server and site domain under Settings, Virling, or the tag inheader.php. - Back in the private window, make one test payment. On WooCommerce, put your gateway in test mode, or turn on Cash on delivery, and place an order as a guest or with a new account; the order should be Processing or Completed and have
virling_vidin its custom fields. With a Stripe Payment Link, connect a restricted key that starts withrk_test_and use a test link. Polar sandbox and Dodo Payments test links do not get the visitor ID, so with those make one small live payment and refund it. - Wait a minute, then open
/app/yourdomain.com/payments. The payment showstestinstead of Unattributed. Open it: Visitor under Details has an ID, and the journey starts at your test visit.
Test payments stay in your reports. On WooCommerce, a later order by the same account keeps the channel of the first one, so check out as a guest or with a new account each time. If a step fails, see test your setup. The UTM builder makes tagged links for your real campaigns.
When a WordPress sale has no source
- The WooCommerce snippet is missing. Without it, orders carry no visitor ID. Orders placed before you added it stay Unattributed.
- You tested as an administrator. The plugin does not load the script for logged-in administrators by default, so there is no visitor ID to pass.
- The link was opened off your site. Checkout links in emails, social posts or QR codes never pass through a page with the script. Send people to your site and let them click through from there.
- The checkout is not a plain link. Embedded checkout widgets, buttons that open the URL from JavaScript and links on a custom checkout domain are not tagged. For those, add the ID yourself from
window.virling.vid(). - Cookieless mode. With cookieless mode on there is no visitor ID to pass, so new payments are Unattributed.
Building on another site builder? See Squarespace revenue tracking and Bubble revenue tracking.
Frequently asked questions
How do I see which channel brought a WordPress sale?
Add the Virling script to every page with the Virling plugin or in your theme's header.php, then make the payment carry the visitor ID. For WooCommerce, a short snippet in functions.php stores it on each order. For Stripe Payment Links and other hosted checkout links, the script adds it to the link by itself. Connect the store or provider, and each sale shows the channel of the visit before it.
Is there a WordPress plugin for Virling?
Yes. Download the integrations/wordpress/virling folder from the Virling repository, upload it to wp-content/plugins, activate it, and enter your Virling server and site domain under Settings, Virling. It adds the script to every page, survives theme updates and skips logged-in administrators by default.
Does the plugin track WooCommerce orders by itself?
No. The plugin adds the tracking script. To tie each order to its visit, add the WooCommerce snippet to functions.php or a snippets plugin, and connect the store with a REST API key that has Read permission. The snippet covers the classic and the block checkout.
How do I track Stripe Payment Links from WordPress?
Link your buttons to the buy.stripe.com URL as it is. The script adds client_reference_id with the visitor ID to every Stripe Payment Link on the page, and Virling reads it from the Checkout Session once you connect Stripe with a restricted key. Polar, Dodo Payments and LemonSqueezy checkout links are tagged the same way.
Why does my WordPress sale show as Unattributed?
The payment carried no visitor ID. Common causes: the WooCommerce snippet is missing, the buyer opened a checkout link from an email or social post instead of your site, you tested while logged in as an administrator with the plugin skipping admins, the checkout opened from an embed or a custom checkout domain, or the script runs in cookieless mode.
Does Virling track the WordPress.com Payment Buttons block?
Only the revenue. The block takes payments through a Stripe account, so if you connect that account to Virling, its charges count. The block is not a checkout link the script can tag, so they show as Unattributed unless they match by email. Use a normal button with a Payment Link to get the channel.
See which channels bring revenue to your WordPress site
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.