Audience: This guide is for developers and technical teams who need to add UTM attribution data to Shopify orders—either backfilling historical orders or capturing UTMs for future orders.
Overview
SourceMedium extracts UTM attribution data from Shopify order-levelcustomAttributes. This guide covers two scenarios:
- Backfilling existing orders — You have attribution data (from spreadsheets, surveys, external tools) and want to write it to historical orders
- Capturing UTMs going forward — You want to automatically capture UTM parameters at checkout for future orders
Backfill Historical Orders
Use the Shopify Admin API to add attribution data to existing orders
Capture Future UTMs
Use Checkout UI Extensions to automatically capture UTMs at checkout
Supported Keys
SourceMedium extracts the following keys fromcustomAttributes. Keys are case-sensitive—use exact lowercase.
| Key | Description | Example Value |
|---|---|---|
utm_source | Traffic source | facebook, google, klaviyo |
utm_medium | Marketing medium | cpc, email, social |
utm_campaign | Campaign name | summer_sale_2025 |
utm_content | Ad content identifier | carousel_v2 |
utm_term | Search term (paid search) | running+shoes |
utm_id | Campaign ID | 120211234567890 |
gclid | Google Click ID | EAIaIQobChMI... |
fbclid | Facebook Click ID | IwAR3x... |
referrer | Referring URL | https://blog.example.com/review |
Backfilling Historical Orders
If you have attribution data for existing orders (e.g., from post-purchase surveys, manual tracking, or external tools), you can write it to Shopify orders so SourceMedium can extract it.How It Works
Available Methods
| Method | Best For | Technical Skill Required |
|---|---|---|
| Shopify Flow | Small batches, no-code users, Shopify Plus | Low (no coding) |
| Admin API Script | Large bulk backfills, automation | Medium (Python/Node.js) |
| Third-Party Apps | Limited - most don’t support order attributes | Varies |
No CSV import available: Unlike products, Shopify does not support CSV import for order attributes. Matrixify and similar bulk import tools also do not support
customAttributes on orders.Option 1: Shopify Flow (No-Code)
If you have Shopify Plus, you can use Shopify Flow with the “Send Admin API request” action. This is ideal for smaller batches or when you want to trigger updates based on conditions.1
Create a Flow workflow
Go to Settings → Flow and create a new workflow. Use a trigger like “Order created” for new orders, or tag orders you want to backfill and trigger on “Order tags added”.
2
Add 'Send Admin API request' action
Select GraphQL Admin API and choose the orderUpdate mutation.
3
Configure the mutation
Use this template to preserve existing attributes while adding new ones:Mutation:Variables (JSON with Liquid):
Option 2: Admin API Script (Bulk)
For large backfills (hundreds or thousands of orders), use a script with the Shopify Admin GraphQL API.Prerequisites
Shopify Admin API access with
write_orders scopeOrder IDs mapped to your attribution data
Attribution data in the supported key format (see table above)
Implementation
- GraphQL Mutation
- Python Script
- Node.js Script
Important Considerations
Merging vs Overwriting Attributes
Merging vs Overwriting Attributes
The
orderUpdate mutation replaces all customAttributes on the order. If the order already has attributes you want to keep:- First, fetch existing attributes via
orderquery - Merge your new attributes with existing ones
- Send the combined array in the mutation
Rate Limits
Rate Limits
Shopify’s Admin API has rate limits. For bulk backfills:
- Use the Bulk Operations API for large datasets
- Or throttle requests to ~2 per second for standard API calls
- Consider batching updates overnight
Order Age Limits
Order Age Limits
Shopify allows updating orders regardless of age, but consider:
- Very old orders may already have SourceMedium attribution from other sources
- Check with SourceMedium support about attribution waterfall priority for your account
Verification
After backfilling:- Verify in Shopify Admin: Orders → [Order] → Additional details should show your attributes
- Wait for sync: SourceMedium syncs typically run every 24 hours
- Check Orders Deep Dive: Verify the attribution appears in SourceMedium dashboards
Capturing UTMs for Future Orders
To automatically capture UTM parameters at checkout for new orders, use a Shopify Checkout UI Extension.This approach supplements your existing tracking (GA4, Elevar). It’s particularly useful when cookie-based tracking fails due to ad blockers or cross-domain issues.
How It Works
Prerequisites
Shopify Plus or ability to create Checkout UI Extensions
Access to deploy changes to your Shopify theme/app
Method to persist UTM params across pages (cookies, localStorage, etc.)
Step 1: Persist UTMs on Landing
Before checkout, you need UTM parameters stored somewhere accessible:- localStorage
Step 2: Create Checkout UI Extension
Step 3: Configure and Deploy
Limitations
Troubleshooting
Attributes appear in Shopify but not SourceMedium
Attributes appear in Shopify but not SourceMedium
- Key name mismatch: Keys must be exact lowercase (
utm_source, notUTM_Source) - Sync timing: Wait 24-48 hours for data to flow through
- Connector version: Ensure your Shopify connector supports
customAttributes(V3 connector required)
Backfill script failing with permission errors
Backfill script failing with permission errors
Ensure your API credentials have
write_orders scope. For private apps, this must be enabled in the app settings.Existing attributes being overwritten
Existing attributes being overwritten
The
orderUpdate mutation replaces all attributes. Fetch existing attributes first, merge, then update.Related Resources
Shopify Admin API - Order Update
Official documentation for the orderUpdate mutation
Shopify Checkout Attributes API
Documentation for useApplyAttributeChange hook
UTM Best Practices
General guidance on UTM naming conventions
Attribution Waterfall
How SourceMedium prioritizes attribution from multiple sources
FAQ
Which method should I use?
Which method should I use?
- Backfill: You have historical attribution data you want to add to existing orders
- Capture going forward: You want to automatically capture UTMs for new orders
- Both: Most brands benefit from backfilling historical data AND capturing future UTMs
What's the priority if multiple sources have UTMs?
What's the priority if multiple sources have UTMs?
SourceMedium uses an attribution waterfall that prioritizes data closest to the transaction. Contact SourceMedium support for your specific configuration.
Can I backfill orders that already have attribution in SourceMedium?
Can I backfill orders that already have attribution in SourceMedium?
Yes, but the waterfall priority determines which source wins. Backfilled
customAttributes data may or may not override existing attribution depending on your configuration.How do I know if my connector supports this?
How do I know if my connector supports this?
SourceMedium’s Shopify V3 connector extracts
customAttributes automatically. Contact support if you’re unsure which connector version you’re on.
