Docs / Integration Tutorials /  

Shopify

Shopify Conversion Tracking And Attribution – How To Set Up

Attribute Shopify purchases to original customer sources to report marketing sources of all purchases, as well as to understand individual customer journeys.

Contents

Track Purchases

Attribute Shopify purchases to original customer sources to report marketing sources of all purchases, as well as to understand individual customer journeys.

Track Purchases

To track Shopify purchases, add the following code to the Settings — Checkout — Additional scripts in Shopify:



<script>
(function() {
 var el = document.createElement('script');
 el.src = 'https://app.ablecdp.com/ue.js';
 el.async = 'true';
 el.addEventListener('load', function() {
  uipe('init', "%%FUNNEL_MARK%%")
  uipe('track', 'Purchase', {
   deal_value: '{{ total_price | money_without_currency }}',
   deal_currency: "{{ currency }}",
   deal_items: [ {% for line_item in line_items %}
    {
     sku: "{{ line_item.sku }}",
     qty: {{ line_item.quantity }},
     price: '{{ line_item.line_price | money_without_currency }}',
    },
   {% endfor %} ],
   order_id: {{ order_number }},
   keys: {
    email: "{{ checkout.email }}",
    phone: "{{ checkout.customer.phone }}",
    client_id: "shopify:{{ checkout.customer.id }}",
   },
   lead: {
    firstName: "{{ checkout.billing_address.first_name }}",
    lastName: "{{ checkout.billing_address.last_name }}",
    city: "{{ checkout.billing_address.city }}",
    country: "{{ checkout.billing_address.country_code }}",
    state: "{{ checkout.billing_address.province_code }}",
    zip: "{{ checkout.billing_address.zip }}",
   },
  })
 })
 document.head.appendChild(el);
})();
</script>

(Where %%FUNNEL_MARK%% is the unique funnel identifier.)

Track Page Views and Visitor Sources

It's strongly recommended to add Able CDP visitor tracking code to the rest of the website pages as well. It records Facebook and Google click ids when a visitor first comes to the website, and uses Google Analytics Client Id in addition ad platform browser ids to better track customers. (Google Analytics must be installed for this tracking script to work correctly.)

This code can be added to Shopify store by editing the theme.liquid template or using GTM.

Visitor tracking code example below supports tracking standard Shopify Lead and Contact forms. It needs to be extended if you're using additional lead generating plugins or landing pages.




<script>
(function() {
 var el = document.createElement('script');
 el.src = 'https://app.ablecdp.com/ue.js';
 el.async = 'true';
 el.addEventListener('load', function() {
  uipe('init', "%%FUNNEL_MARK%%");
  uipe('track', 'PageView');
  (function() {
  var leadForm = document.getElementById('contact_form');
  if (leadForm) {
  leadForm.addEventListener('submit', function () {
   var leadParams = {
    keys: {
  email: leadForm.elements['contact[email]'] && leadForm.elements['contact[email]'].value, phone: leadForm.elements['contact[phone]'] && leadForm.elements['contact[phone]'].value
    }, lead: {
  
    }
   };
   uipe('track', 'Lead', leadParams);
  });
  }
  })(); 
 });
 document.head.appendChild(el);
})();
</script>

Next Steps

After Shopify purchases begin to appear in Able CDP under Customers — Purchases tab, set up one or a few of the supported outbound Purchase conversion integrations listed below. If you're currently sending Purchase events to the same service using another integration or tracking code, it's recommended to disable sending Purchase conversions with it and only send Purchase conversions using Able CDP Conversions API integration to prevent duplicates.

If Duplicate Purchase conversions appear in Facebook Ads Manager or duplicate events warning appears in Facebook Events Manager

When Able is used, conversion events that are sent by it to the Facebook Conversions API should not be sent using Facebook Pixel as it'll lead to event duplication.

Able doesn't send deduplication parameters in its Conversions API calls as it'll lead to additional customer tracking data collected by Able CDP and sent to Conversions API to be ignored altogether in favor of the Pixel event. This is done by design on the Facebook end.

To prevent duplicates from appearing, send PageView events to Facebook Pixel from the browser and use Able to send Lead and Purchase events attributed to the original visitor.

Doing this in Shopify requires the following steps:

  1. Disable Shopify Facebook Data Sharing
  2. Edit Shopify theme and add Facebook Pixel code using the instructions to Manually add pixel code to website

This should resolve event duplication issues by making sure that each type of event is sent to Facebook Pixel and Conversions API once.