This document describes how to track visitor behaviour in Shopify.
Track purchases
To track purchases in Shopify, you can insert a small tag into your store that Optimize will pick up and capture.
Login to your store's admin area
Go to Settings > Checkout > Order Processing > Additional Scripts
Add the below code into the box, and then click the Save button that appears in the bar across the top of the page.
Note: you will need your account's tag - details for finding it are here if needed: https://help.webtrends-optimize.com/optimize/setup-optimize/integrations-javascript-tag/installing-webtrends-optimize-into-a-shopify-store/
โ
<script type="text/javascript" id="wto-purchase-tracking">
window.opt_data = window.opt_data || [];
{% assign wt_qty = 0 %}
{% for i in order.line_items %}
{% assign wt_qty = wt_qty | plus: i.quantity %}
{% endfor %}
opt_data.push({
event: "Purchase",
data: {
orderid: "{{ order_number }}",
revenue: {{ total_price | money_without_currency }},
units: {{wt_qty}}
}
});
var sc = document.createElement('script');
sc.src = "//c.webtrends-optimize.com/acs/accounts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/js/wt.js";
document.body.appendChild(sc);
</script>
This code achieves two things - collecting the attributes we want to track, and also writing your tag to the page which is necessary if you aren't a Shopify Plus customer.
Note: the code in the above screenshot may differ and is just for illustrative purposes - please use the code provided at the top of this document instead
You will also need a conversion package script added to your tag. If you don't already have one, please talk to your Optimisation Consultant to get one added.
Once done, you can add the following metrics to your test, or set them up in Account Settings > Automatic Conversions for them to be added automatically. If you need help doing this, again please contact your Optimisation Consultant who can help.
orderid
- type: textrevenue
- type: decimalunits
- type: integer