How to Automatically Add UTM Parameters to All Shopify Links?

How to Automatically Add UTM Parameters to All Shopify Links?


📌 Why Should You Add UTM Parameters Automatically?

If you're running ads, email campaigns, or social posts that link to your Shopify store, you need UTM parameters to:

  • Track source and performance in GA4

  • Attribute conversions correctly

  • Understand which channels are driving revenue

But manually tagging every URL is time-consuming and error-prone.

So let’s set up automatic UTM tagging across Shopify — the smart, scalable way.


🤔 What Are UTM Parameters?

UTM parameters are tags you add to your URLs to tell analytics platforms where traffic is coming from.

Example:

https://yourstore.com/products/shoes?utm_source=facebook&utm_medium=ads&utm_campaign=spring_sale

Each tag gives GA4 (or any analytics tool) context about the visit.


âś… Ways to Automatically Add UTM Parameters on Shopify


1. Use Shopify's Built-in Link Builder for Marketing Campaigns

Shopify’s Marketing section lets you create campaigns and will automatically tag URLs with UTMs.

Steps:

  • Go to Shopify Admin > Marketing

  • Create a new campaign (e.g., Facebook Ad, Email)

  • Shopify appends UTM tags like:

    utm_source=shopify&utm_medium=facebook&utm_campaign=spring_sale
    

But this works only for campaigns built inside Shopify.


2. Add UTM Parameters Dynamically in Theme Code

If you want to auto-append UTM parameters to specific links, you can do it via JavaScript in your theme.

Use this snippet in theme.liquid before the closing </body> tag:

<script>
  document.addEventListener("DOMContentLoaded", function() {
    const links = document.querySelectorAll('a[href*="/products/"]');
    const utm = "?utm_source=website&utm_medium=link&utm_campaign=shopify_auto";
    links.forEach(link => {
      if (!link.href.includes("utm_")) {
        link.href += utm;
      }
    });
  });
</script>

âś… Adds UTM to all product links
❌ Doesn’t work for image-only or button-based links (without href)


3. Use a URL Redirect App to Append UTM Automatically

Apps like:

Let you set rules to automatically append UTMs to:

  • Email campaigns

  • Paid traffic

  • Referral sources

These apps can sync with GA4 and even tag based on session data.


4. Add UTM Tags to Klaviyo Email Links Automatically

If you’re using Klaviyo (or any email tool), you can configure auto UTM parameters.

Steps for Klaviyo:

  • Go to Account > Settings > Email

  • Enable default UTM tags:

    utm_source=klaviyo&utm_medium=email&utm_campaign={{ campaign.name }}
    

Every link in your emails will now include those tags, automatically.


5. Use Google Tag Manager (GTM) for Dynamic UTM Capture (Advanced)

With GTM, you can:

  • Capture UTM parameters from the landing URL

  • Store them in cookies

  • Send them along with every GA4 event for attribution

Example:

gtag('event', 'page_view', {
  campaign_source: getUTM('utm_source'),
  campaign_medium: getUTM('utm_medium'),
  campaign_campaign: getUTM('utm_campaign')
});

This doesn’t add UTMs to links but ensures attribution still works even if user navigates multiple pages.


đź§Ş Bonus: Track UTM in GA4 Events & Conversions

Make sure to enable custom dimensions in GA4 for:

  • utm_source

  • utm_medium

  • utm_campaign

This allows you to segment purchases by source directly inside GA4 reports and Explorations.


🛑 Mistakes to Avoid

Mistake Fix
Manually tagging every link Use dynamic code or a UTM app
Forgetting to tag email links Set global UTM rules in Klaviyo or app
Ignoring post-click attribution Use GTM to store UTM in cookies
Duplicating UTMs on links Add a check in script (!link.href.includes("utm_"))

âś… Summary

Method Ideal For Difficulty
Shopify Marketing builder Ad/email campaigns in Shopify Easy
JavaScript auto-appender Site-wide product/internal links Moderate
UTM apps Scaling campaigns & reporting Easy
GTM + cookies Deep attribution tracking Advanced

🤝 Need Help Setting Up UTM Tracking That Scales?

At RootSyntax, we help eCommerce brands streamline UTM setup and unlock deeper insights in GA4 and Klaviyo.
👉 Reach out here to automate your campaign tracking.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.