How to Create GTM Triggers to Monitor Discount Code Usage on Your Shopify Site for Tracking Referral Assisted Conversions

Hey there! in today’s GTM Guide, I’m going to explain how you can create Google Tag Manager (GTM) triggers to monitor discount code usage on your Shopify site. By tracking how frequently your discount codes are used, you’ll gain valuable insights into the effectiveness of your promotional campaigns, helping you optimize your sales strategies!

What You’ll Learn:

  1. How to set up a custom event in Google Tag Manager to track discount code usage.
  2. How to implement data layer pushes in your Shopify site using JavaScript.
  3. How to test and verify the custom event using Google Tag Manager Preview.

So let’s dive right in!

Set Up a Custom Event in Google Tag Manager

First things first, we need to set up a custom event in GTM that will serve as our trigger for tracking discount code usage. Follow these steps:


  1. Log in to your Google Tag Manager account and select your desired container.
  2. On the left, click on “Triggers,” then click “New” to create a new trigger.
  3. Name the trigger “Discount Code Usage” or any suitable name of your choice.
  4. Select “Custom Event” as the trigger type.
  5. Set the event name as “discountCodeUsed.”
  6. Click “Save.”


Step 2: Implement Data Layer Pushes in Your Shopify Site

Now, we need to push data layer events with the necessary information every time a discount code is used on your Shopify site. To do this, we’ll use JavaScript. Just follow these steps:

  1. Log in to your Shopify account, head to the “Online Store” section, then click “Themes.”
  2. Click “Actions” and then “Edit Code.”
  3. Find and open the “cart.liquid” file from your theme’s templates.
  4. Look for the following line: `<form action=”/cart” method=”post” novalidate class=”cart”>`
  5. Add the following JavaScript code snippet right after the line you found above:
  {% if %}
    window.dataLayer = window.dataLayer || [];
      event: 'discountCodeUsed',
      discountCode: '{{ }}',
      discountAmount: '{{ | money }}'
  {% endif %}
  1. Save your changes.

The above script checks if a discount code is applied to the cart and then pushes the discount code and saved amount into the data layer when the condition is met.

Step 3: Test and Verify the Custom Event

Let’s check if everything is working correctly.

  1. On the Google Tag Manager dashboard, click “Preview” to enable preview mode.
  2. In a new browser tab, visit your Shopify site.
  3. Apply a discount code to your cart.
  4. In the Google Tag Manager preview pane at the bottom of the site, you should see the “discountCodeUsed” event in the “Summary” section along with the code and saved amount.

That’s it! You’ve successfully set up a custom event for tracking discount code usage in your Shopify store using Google Tag Manager. You can now leverage this information within your marketing tools to better assess the performance of your promotional campaigns and boost your sales strategy.

Monitoring discount code usage on your Shopify site empowers you to make more informed decisions about your promotions and offers. With Google Tag Manager and a little bit of JavaScript, you now have the ability to track and analyze discount code usage for better sales performance. Cheers to smarter, more efficient promotional strategies!