utm-tracking shopify attribution how-to

How to Track UTM Parameters on Shopify Orders (Complete Guide)

Detectly Team

You’re spending money on ads across Meta, Google, TikTok, email, and influencers. Sales are coming in. But when you look at an individual Shopify order, you have no idea which channel actually drove it.

Shopify doesn’t natively save UTM data on orders. It tracks sessions in analytics, but that information doesn’t carry through to the order itself. So when you’re looking at your orders list, you can’t tell if Order #1042 came from your Facebook retargeting campaign or from an influencer’s Instagram Story.

UTM tracking fixes this. Here’s how it works, why Shopify makes it harder than it should be, and how to set it up properly.

What Are UTM Parameters?

UTM (Urchin Tracking Module) parameters are tags you add to the end of a URL. When someone clicks a link with UTM parameters, analytics tools can read those tags and know exactly where the visitor came from.

There are five standard UTM parameters:

ParameterPurposeExample
utm_sourceWhere the traffic comes fromfacebook, google, newsletter
utm_mediumThe type of trafficcpc, email, social, referral
utm_campaignThe specific campaignspring_sale, black_friday_2026
utm_contentWhich ad or link variantvideo_ad_v2, hero_banner
utm_termThe search keyword (for paid search)blue+running+shoes

A fully tagged URL looks like this:

https://yourstore.com/collections/new?utm_source=facebook&utm_medium=cpc&utm_campaign=spring_2026&utm_content=carousel_ad_3

When a customer clicks this link, you know they came from a Facebook paid ad, from your Spring 2026 campaign, specifically from carousel ad variant 3.

The Problem: Shopify Doesn’t Save UTMs on Orders

Here’s where things get frustrating. Shopify’s analytics can read UTM parameters and show them in session reports. But when that visitor becomes a customer and places an order, the UTM data is not attached to the order.

You can see in Shopify Analytics that you had 200 sessions from utm_source=facebook. But you can’t see which of your 50 orders today came from those specific sessions.

This means you’re flying blind on the most important question: which campaigns actually generate revenue?

Approach 1: Google Analytics (Free, But Limited)

Google Analytics 4 (GA4) reads UTM parameters automatically. If you have GA4 installed on your Shopify store, it will track which campaigns drive traffic and even attribute conversions.

The Limitations

  • Session-based, not order-based: GA4 tells you a conversion happened from a campaign, but doesn’t connect it to a specific Shopify order number
  • Sampling: GA4 uses data sampling on larger stores, meaning your numbers are estimates
  • Cross-device gaps: If someone clicks on mobile and buys on desktop, GA4 may not connect the dots (unless they’re logged into Google)
  • Consent and blockers: Ad blockers and cookie consent banners can prevent GA4 from firing, meaning lost data
  • No order-level export: You can’t export a list of orders with their UTM sources from GA4

GA4 is good for understanding traffic patterns. It’s not great for knowing “did my Facebook campaign actually make money?”

Approach 2: Manual Spreadsheet Tracking

Some merchants try a manual approach:

  1. Export Shopify orders
  2. Export GA4 conversion data
  3. Try to match timestamps and amounts
  4. Manually tag orders in a spreadsheet

This technically works for very small stores doing fewer than 10 orders a day. For anyone beyond that, it’s unsustainable. You’ll spend hours on data reconciliation that could be spent growing your business.

When Manual Makes Sense

  • You’re just starting and have fewer than 5 orders per day
  • You only run ads on one platform
  • You want to validate the concept before investing in a tool

Approach 3: Custom Code (Technical, Fragile)

If you’re comfortable with code (or have a developer), you can build a DIY solution:

  1. Add JavaScript to your theme that reads UTM parameters from the URL
  2. Store them in a cookie or localStorage
  3. Pass them to Shopify via cart attributes or a hidden form field at checkout
  4. Read them via Shopify’s order API

The Code Approach — What’s Involved

Step 1: Capture UTMs on landing

You need JavaScript on every page that checks for UTM parameters in the URL and stores them:

// Simplified example
const params = new URLSearchParams(window.location.search);
const utmFields = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];

utmFields.forEach(field => {
  const value = params.get(field);
  if (value) {
    sessionStorage.setItem(field, value);
  }
});

Step 2: Attach to cart/checkout

You then need to inject these values into the cart as note attributes or line item properties before checkout.

Step 3: Handle edge cases

This is where DIY solutions usually break:

  • What if the customer visits multiple pages before adding to cart?
  • What if they close the browser and come back?
  • What if they use a different device?
  • What about Shopify’s checkout on a separate domain?
  • What about sessions that start on one UTM and continue from another?

Custom solutions tend to work well initially but break over time as Shopify updates its checkout, themes change, or edge cases accumulate.

The most reliable approach is using a purpose-built Shopify app that handles UTM capture automatically. These apps typically:

  1. Inject a script via Shopify’s theme app extensions (no manual code needed)
  2. Capture UTMs on first visit and persist them through the session
  3. Attach data to orders via order metafields or note attributes
  4. Handle edge cases like returning visitors, multi-page journeys, and checkout redirects

What to Look For in a UTM Tracking App

  • Theme app extension (not manual script injection that breaks on theme updates)
  • First-party data capture (doesn’t rely on third-party cookies)
  • Order metafield storage (data lives on the order, exportable and queryable)
  • First-touch and last-touch tracking (both matter)
  • Shopify Flow compatibility (so you can automate based on UTM data)

Detectly is one option that takes this approach. It uses Shopify’s official theme app extensions and web pixel API to capture UTM data, then writes it to order metafields automatically. Each order gets tagged with the full UTM breakdown, which you can see directly in the Shopify admin, use in Shopify Flow automations, or export for analysis.

Setting Up UTM Tracking: A Practical Checklist

Regardless of which approach you choose, you need to get the fundamentals right first.

Step 1: Create a UTM Naming Convention

Before you tag a single URL, decide on a naming convention. Inconsistent UTMs are worse than no UTMs because they fragment your data.

Good convention:

ParameterFormatExamples
sourcePlatform name, lowercasefacebook, google, tiktok, klaviyo
mediumTraffic type, lowercasecpc, cpm, email, social, influencer
campaignDescriptive, lowercase, underscoresspring_sale_2026, retargeting_atc
contentAd variant identifiervideo_v1, carousel_lifestyle, ugc_review
termKeyword or audiencebroad_interest_fitness, lookalike_purchasers

Bad examples to avoid:

  • Mixing cases: Facebook vs facebook vs FACEBOOK (these are three different sources)
  • Spaces in values: spring sale (breaks URLs)
  • Generic names: campaign1, test, ad (meaningless in reports)

Step 2: Tag All Your Ad URLs

For every ad platform, add UTM parameters to your destination URLs.

Meta Ads: Use URL parameters at the ad level. You can use Meta’s dynamic parameters:

?utm_source=facebook&utm_medium=cpc&utm_campaign={{campaign.name}}&utm_content={{ad.name}}&utm_term={{adset.name}}

Google Ads: Use the tracking template or final URL suffix:

?utm_source=google&utm_medium=cpc&utm_campaign={campaignname}&utm_content={creative}&utm_term={keyword}

Email (Klaviyo, Mailchimp, etc.): Tag every link in every email:

?utm_source=klaviyo&utm_medium=email&utm_campaign=welcome_flow_email_3

Don’t forget about organic and owned channels:

  • Instagram bio link: Add UTMs so you can distinguish bio clicks from ad clicks
  • TikTok bio: Same idea
  • Influencer links: Give each influencer a unique UTM so you can track their performance
  • QR codes: Tag the destination URL behind the QR code

Step 4: Verify Your Setup

After setting everything up:

  1. Click one of your tagged links
  2. Check that you land on your store with the UTMs visible in the URL bar
  3. Complete a test purchase
  4. Check the order in Shopify — can you see the UTM data?

If you’re using an app like Detectly, the UTM fields should appear as metafields on the order detail page. If you built a custom solution, check your cart note attributes.

What You Can Do With Order-Level UTM Data

Once you have UTMs on every order, you unlock several powerful capabilities:

True Campaign ROAS

Instead of trusting Meta’s inflated ROAS number, calculate it yourself: take the revenue from orders tagged with utm_campaign=spring_sale and divide by your actual ad spend. That’s your real return.

Channel Comparison

Export your orders and group by utm_source. Now you can see real revenue by channel — not modeled conversions, not estimated attribution, but actual orders with actual revenue.

Ad Creative Performance

Using utm_content, you can see which ad creative actually drives purchases, not just clicks. That video ad might get great click-through rates but terrible conversion rates. UTM data tells you the truth.

Customer Segmentation

Tag orders by acquisition channel and track lifetime value by source. Maybe your email customers have 2x the LTV of your Facebook customers. That changes how much you should be willing to pay for each.

Shopify Flow Automations

With UTMs stored as order metafields, you can build Shopify Flow automations:

  • Tag customers by acquisition channel
  • Send different post-purchase emails based on source
  • Flag high-value orders from specific campaigns for personal follow-up

Common UTM Mistakes to Avoid

  1. Not tracking at all — Even imperfect tracking is better than none
  2. Inconsistent naming — Decide on a convention and stick to it
  3. Only tracking paid ads — Tag email, social, influencer, and referral links too
  4. Forgetting mobile — Make sure your tracking works on mobile browsers
  5. Not testing — Always verify with a test purchase after setup
  6. Changing conventions mid-campaign — This fragments your historical data

Start Today

You don’t need a perfect system on day one. Start by tagging your top-spending ad campaigns with consistent UTMs. Set up a way to capture that data on orders (whether that’s a manual approach, custom code, or an app). Then gradually expand to cover all your traffic sources.

The merchants who know exactly where their revenue comes from are the ones who scale profitably. Everyone else is guessing — and guessing gets expensive fast.

Ready to see your true ROAS?

Detectly tracks every UTM, attributes every Shopify order, and shows you which channels actually drive revenue.