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

How to track WooCommerce revenue by traffic source

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

To track WooCommerce revenue by traffic source, give each visitor an ID, save it on the order when checkout creates it, and join each order back to the visits that came before it. WooCommerce knows who ordered and how much. Its built-in order attribution can show an origin, but it relies on short-lived cookies and a script that has to run on every page, and many orders end up as Unknown.

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 in your theme so it runs on every page of the store, including the product, cart and checkout pages, and on any blog or landing page that links to the store. Because the ID lives in a cookie on your own domain, WordPress receives it with every request from the browser, so the server can read it at checkout without any extra JavaScript.

Step 2: save the ID on the order

WooCommerce orders carry meta data, so the ID can travel with the order. Hook into order creation and copy the ID from the cookie into the order's meta. WooCommerce has two checkouts, the classic shortcode checkout and the newer block checkout, and each fires its own hook when it builds the order, so use both:

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);
}

Put it in your theme's functions.php or in a snippets plugin. A snippets plugin is often the safer home, because a theme update can replace functions.php. The pattern check means only a well-formed ID is saved, and an order placed without the cookie simply gets no ID.

Step 3: read orders from the REST API

In WordPress, open WooCommerce, Settings, Advanced, REST API, and add a key with Read permissions. A read-only key is all an analytics tool needs: it reads orders, refunds and subscriptions, and never changes them. The store has to answer over https, with pretty permalinks on, so that /wp-json/wc/v3/ works.

Decide which order statuses count as paid. Processing and completed orders have been paid. Failed and cancelled orders have not. Pending and on-hold orders are not paid yet, so wait for them to move on instead of counting or dropping them straight away.

Step 4: join orders to visits

Match each order's virling_vid to that visitor's earlier visits and credit one of them with a rule you keep fixed (see first touch or last touch). Orders with no ID have no visit to join, so they show as Unattributed. They still count toward revenue, so your totals stay right even when the channel is missing.

WooCommerce allows guest checkout. Guest orders have no customer ID, so each one counts as its own customer. That is worth knowing before you read a customers column next to a revenue column.

For each channel with at least three matched first orders, Virling's Time to pay card shows the median time from a WooCommerce customer's first visit to that order.

Start free trial See the demo

Step 5: handle refunds and renewals

Two things change the numbers after the first order. Refunds lower an order's revenue, and they can arrive weeks after the sale, so read recent orders again from time to time to catch them. Otherwise a channel that looks good on day one keeps looking good after its buyers asked for their money back.

If you sell subscriptions with WooCommerce Subscriptions, each renewal is a new order created without a store visit, so it carries no visitor ID of its own. Mark renewal orders as renewals and give them the channel of the customer's first payment, or they will pile up as Unattributed and the channel that won the customer will look smaller than it is.

Step 6: report revenue per channel

Group the joined orders by channel and divide by visitors to get revenue per visitor. That is the table that tells you where to spend time and ad budget: a channel with fewer visitors can still bring more revenue per visitor than a busy one.

Example data, made up to show the method: one month for an imaginary WooCommerce store.

ChannelVisitorsOrdersRevenueRevenue per visitor
Organic search4,20042$2,814$0.67
Paid2,60031$1,664$0.64
Social1,9009$456$0.24
Direct1,15014$851$0.74
Email64023$1,472$2.30
Unattributed6$318
All10,490125$7,575$0.72

Email sends the fewest visitors but earns $2.30 each, over three times the store's $0.72, so a signup form on product pages is likely worth more than another social post; Social sends 1,900 visitors at $0.24 each, so check which posts bring buyers before spending more time there. Set Paid's $1,664 against what you spent on ads, and look at the 6 unattributed orders for admin-created orders or a missing block checkout hook.

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

What goes wrong

  • Hooking only the classic checkout, so orders from the block checkout arrive with no visitor ID
  • Losing the snippet in a theme update because it lived in a theme you do not control
  • Orders created in the admin, through the REST API or by import, which have no web visit and so no visitor ID
  • Counting pending and on-hold orders as revenue before they are paid
  • Ignoring refunds, which overstates a channel

Doing it with Virling

Virling reads WooCommerce orders, their refunds and, with WooCommerce Subscriptions, subscriptions from your store's REST API with a read-only key. In Virling, paste the consumer key and the consumer secret joined by a colon, as ck_...:cs_..., and enter your store's address, such as https://shop.example.com.

It imports orders from the last 90 days on the first run, then new ones every minute. Processing and completed orders count as paid, failed and cancelled ones as failed, and pending and on-hold orders wait until they are paid. Each order's refunds lower its revenue, and orders from the last 60 days are read again every 6 hours so later refunds show up. With WooCommerce Subscriptions, renewal orders are marked as renewals and keep the channel of the first payment, and subscription status is read once an hour so Retention can tell who still pays. Without it, Retention uses payment recency.

Virling reads the ID from virling_vid in the order's meta data, which is what the snippet above saves. Add it once, make a test order from a page that runs the script, and after the next sync the order shows a channel instead of Unattributed in the payments list. The setup is in the docs and on the WooCommerce integration page.

Frequently asked questions

Can WooCommerce show which traffic source an order came from?

Partly. WooCommerce order attribution shows an origin for some orders, and the rest show as Unknown. For a view you control, save a visitor ID on each order and join it to that visitor's earlier visits in your analytics.

Where does the visitor ID go in WooCommerce?

In the order's meta data, under virling_vid. A short snippet in your theme's functions.php, or in a snippets plugin, copies it from the virling_vid cookie when the order is created, in the classic and the block checkout.

Which channel do WooCommerce subscription renewals get?

With WooCommerce Subscriptions, a renewal order is marked as a renewal and keeps the channel of the customer's first payment.

What kind of REST API key does Virling need?

A WooCommerce REST API key with Read permissions. Virling only reads orders, refunds and subscriptions, so it never needs write access.

See your WooCommerce 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