How to track Shopify revenue by traffic source
By Devendra Variya, co-founder of Virling. Published 2026-11-12, updated 2026-11-25.
To track Shopify revenue by traffic source, give each visitor an ID, store it on the cart so Shopify copies it onto the order, and join each order back to the visits that came before it. Shopify knows who ordered and how much. It does not know which page or channel brought them, and many orders end up as Direct.
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, and on any blog or landing page that links to it.
Step 2: store the ID on the cart
Shopify copies cart attributes onto the order as note attributes. So add a small snippet to theme.liquid, after the analytics script, that reads the visitor ID and posts it to /cart/update.js as a cart attribute. Now every order carries the visitor who placed it. If the snippet can run before the analytics script has loaded, run it on the page load event, or the value will be empty.
This is the snippet for Virling. It already waits for the load event:
<script>
// Shopify: in your theme's theme.liquid, after the Virling script.
// It stores the visitor ID on the cart, and Shopify copies cart
// attributes onto the order as note attributes.
addEventListener("load", function () {
var vid = window.virling && virling.vid && virling.vid();
if (vid) fetch("/cart/update.js", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ attributes: { virling_vid: vid } })
});
});
</script>A headless store, built with Hydrogen or another custom storefront, has no theme.liquid, and /cart/update.js only exists on the Online Store. Set the same virling_vid cart attribute from your own cart code through the Storefront API instead. Shopify copies it onto the order the same way. The code is in Shopify Hydrogen UTM tracking.
Step 3: read orders and join them to visits
Read paid orders from Shopify with a token that can only read orders, then match each order's visitor ID to that visitor's earlier visits. Credit one of them with a rule you keep fixed (see first touch or last touch).
How Virling matches an order
Virling tries two things, in this order:
- Visitor ID. It reads
virling_vidfrom the order's note attributes. - Customer email. For an order with no visitor ID, it compares the order's email with emails your site sent as
identifyevents, for example right after signup. A match credits that visitor, and the payment shows Matched by email.
The email match has limits. It is exact, apart from capitals and spaces around the address, so a customer who orders with a different email is not matched. It never crosses sites, and it only applies to orders synced after the identify event. Virling keeps the emails your site sends only as salted hashes. UTM tags that Shopify stores on the order, and the landing page, are not read. An order that matches neither way still counts toward revenue, as Unattributed, and so does one whose visitor has no visit inside the lookback window. The event is in recover payments by email.
For the orders it matches, the Landing page tab on Virling's Pages card shows the Shopify revenue credited to visits that began on each page.
Step 4: handle refunds and renewals
Two things change the numbers after the first order. Refunds lower an order's revenue, so a channel that looks good on day one can shrink later. Orders from a subscription renewal carry no cart attribute of their own, so they should keep the channel of the customer's first payment instead of ending up with no source. In Virling, Shopify Subscriptions renewals and any later order by the same customer keep the channel of that customer's first order. How a subscription store compares channels by the subscribers who keep paying is in Shopify subscribers by channel. An order from a subscription app with another source is tied to the first order only through the customer.
Step 5: 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.
Here is what it can look like for one month. The store and every number are made up:
| Channel | Visitors | Orders | Revenue after refunds | Revenue per visitor |
|---|---|---|---|---|
| Organic search | 4,000 | 60 | $3,600 | $0.90 |
| Paid | 2,500 | 50 | $3,000 | $1.20 |
| 800 | 32 | $1,920 | $2.40 | |
| Social | 5,000 | 25 | $1,250 | $0.25 |
| Direct | 3,000 | 45 | $2,700 | $0.90 |
Social brings the most visitors and the least revenue, while Email brings the fewest visitors and earns the most from each one. Paid beats Organic search per visitor, $1.20 to $0.90, but that is before the cost of the ads, so subtract your ad spend before you raise the budget.
Checkout on another domain, a subdomain or a second site? See cross-domain checkout attribution.
What goes wrong
- Skipping step 2: orders arrive with no visitor ID, and those with no email match either have no source
- Running the snippet before the analytics script has loaded, so the cart attribute is empty
- Draft, POS and staff-created orders, which are not made from a storefront cart and so carry no visitor ID. They can still match by email
- Counting only paid orders and ignoring refunds, which overstates a channel
Doing it with Virling
Virling reads Shopify orders and their refunds with the Admin API token of a custom app that has only the read_orders scope. It imports the last 60 days on the first run, the most Shopify gives without the read_all_orders permission, then new orders every minute, and it does the join for you. It reads the ID from virling_vid in the order's note attributes, and tries the order's email when there is none. Paid, partially refunded and refunded orders count; pending and authorized orders wait until they are paid. The snippet is in the docs, and the setup is on the Shopify integration page.
Frequently asked questions
Can Shopify show which traffic source an order came from?
Only partly. Shopify's own reports show a source for some orders, and many land in Direct. For a view you control, store a visitor ID on the cart and join each order to that visitor's earlier visits in your analytics.
Where do I put the visitor ID in Shopify?
On the cart, as an attribute. Shopify copies cart attributes onto the order as note attributes, so the order carries the visitor ID. A short snippet in theme.liquid, after your analytics script, does it.
Which channel do Shopify subscription renewals get?
An order from a Shopify Subscriptions renewal is marked as a renewal and keeps the channel of the customer's first payment.
How far back does the first import go?
Virling imports the last 60 days of orders on the first run, the most Shopify gives without the read_all_orders permission, then new orders every minute.
Are Shopify draft and POS orders linked to a visit?
Not by visitor ID. They are not made from a storefront cart, so they have no virling_vid. The order is credited to a visit only if its email matches an identify event your site sent, or if it is a later order by a customer whose first order was credited. Otherwise it counts as revenue and stays Unattributed.
What happens to orders imported from before the snippet?
They count as revenue but are Unattributed, because their carts stored no visitor ID. An order whose email matches an identify event sent before the order was synced is credited to that visitor, if a visit of theirs falls inside the lookback window before the order. Most imported orders were made before the script was on your store, so expect few of these.
See your Shopify 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.