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"></script> Step 2: Open the theme editor
- In your Shopify admin, go to Online Store > Themes
- Find your active theme and click the three-dot menu (⋯), then Edit code
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"></script>
</head> - Click Save
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
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) - you’ll need to add hidden fields to the form. SourceTag detects the form and populates any matching fields on submission
- 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
You’ll need to add hidden fields to whichever form you’re using. SourceTag doesn’t create fields - it only fills in fields that already exist. See Add Hidden Fields for the field names.
For checkout forms and order data, SourceTag tracks the attribution cookie but can’t add fields to 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.
Doesn't answer your question or need more help? Get in touch.
