Installation
Install SourceTag on Shopify
Add SourceTag’s tracking script to your Shopify store by editing the theme code. You’ll paste the script tag into your theme’s <head> section.
Step 1: Copy your script tag
In your SourceTag dashboard, go to your site’s detail page and copy the script tag. It looks like:
<script src="https://cdn.sourcetag.io/scripts/YOUR_SITE_ID/st.js" async></script> [IMAGE: Screenshot of the SourceTag dashboard showing the script tag on the site detail page]
Step 2: Open the theme editor
- In your Shopify admin, go to Online Store > Themes
- Find your active theme and click Actions > Edit code (or the three-dot menu, then Edit code)
[IMAGE: Screenshot of Shopify admin showing Online Store > Themes with the Edit code option]
Step 3: Edit theme.liquid
- In the left sidebar, under Layout, click theme.liquid
- Find the closing
</head>tag in the file - Paste the SourceTag script tag on the line directly above
</head>
<!-- SourceTag attribution tracking -->
<script src="https://cdn.sourcetag.io/scripts/YOUR_SITE_ID/st.js" async></script>
</head> - Click Save
[IMAGE: Screenshot of the Shopify code editor with the SourceTag script tag pasted above the closing head tag in theme.liquid]
Step 4: Test
Visit your live Shopify store with UTM parameters:
https://yourstore.myshopify.com/?utm_source=test&utm_medium=cpc&utm_campaign=shopify-test Open your browser’s developer tools (F12 or Cmd+Option+I on Mac) and check:
- View page source to confirm the script tag appears in the
<head> - Application > Cookies to confirm a
_sourcetagcookie has been created - If you have a contact form or enquiry form on your store, submit it and check the notification for attribution data
[IMAGE: Screenshot of browser developer tools showing the _sourcetag cookie on a Shopify store]
Shopify forms
Shopify doesn’t have a built-in form builder in the same way WordPress does. Most Shopify stores use one of these for lead capture:
- Contact page (pages/contact.liquid) - SourceTag detects the native contact form and adds hidden fields automatically
- Third-party form apps (JotForm, Typeform, etc.) - if the form renders as an HTML
<form>element or iframe, SourceTag will detect it via MutationObserver - Custom Liquid forms - if you’ve built custom forms in Liquid templates, SourceTag detects those too
For checkout forms and order data, SourceTag tracks the attribution cookie but doesn’t inject hidden fields into the Shopify checkout (which is locked down). To pass attribution data into orders, you’d typically use a post-purchase webhook or Shopify Flow to read the cookie data.
Notes
- This approach works on all Shopify plans that allow theme editing.
- The script loads on every page of your store, including product pages, collection pages, and the cart.
- Browser cookies are limited to 7 days on Shopify. There’s no server-side cookie option for Shopify sites. See Safari Cookies for details.
- If you change or update your theme, you’ll need to re-add the script tag to the new theme’s
theme.liquid.