Capturing UTM Parameters in Shopify's landing_site field with order webhook

To track where your customers come from, add some magic UTM parameters to your product links and configure your Shopify store to capture them. It's like casting a spell that captures the parameters and stores them in the "landing_site" field of the shipping address. And voila! You'll have the power of ecommerce magic at your fingertips.

In Shopify, you can easily add UTM tracking parameters to your product links and capture them in the landing_site field when you receive an order webhook.

Here is a quick way to do so:

  1. Login to your Shopify store and go to the “Online Store” section.
  2. Click on “Preferences” and scroll down to the “Google Analytics” section.
  3. Under “Additional Google Analytics JavaScript”, add the following code:

{% if first_time_accessed %}
  ga('set', 'campaignName', '{{ request.params.utm_campaign }}');
  ga('set', 'campaignSource', '{{ request.params.utm_source }}');
{% endif %}

This code will capture the UTM parameters from the URL when the customer first accesses your store and set them as custom variables in Google Analytics.

  1. Save the changes and go to the “Settings” section of your store.
  2. Click on “Checkout” and scroll down to the “Order processing” section.
  3. Under “Additional scripts”, add the following code:
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
var utm_params = new URLSearchParams(window.location.search);
if (utm_params.has('utm_source') && utm_params.has('utm_campaign')) {
var landing_site_field = document.querySelector("#checkout_shipping_address_landing_site");
if (landing_site_field) {
landing_site_field.value = window.location.href;
}
}
});
</script>

This code will capture the UTM parameters from the URL when the customer places an order and store the URL in the “landing_site” field of the shipping address.

  1. Save the changes. Grab a coffee.

We’ll help you set it up —

Need help setting up your Shopify UTMs?

Contact Us →

0 Comments

    Leave a Reply