Shopify Tracking Setup
ShareASale’s tracking for Shopify involves two 'tags,' which are snippets of code installed in the Checkout settings of Shopify’s admin and in the central theme.liquid template. The first tag is for tracking conversions (i.e. sales) and the second for assisting with Affiliate click attribution accuracy in certain browsers. Installation of both should be simply copy and paste of the code included herein.
Conversion Tracking Pixel Installation
Open your Shopify store’s admin page and click the Settings button in the bottom left corner. Then, click the Checkout and accounts tab in the settings list.
Scroll down to the section labeled Order status page. In the field labeled Additional Scripts, add the below code.
Replace the XXXXX in the code below (Line 4) with your ShareASale Merchant ID. You can find this at the top-left of your ShareASale account when you are logged in.
Replace the !!!!!! in the code below (Line 53) with your Master Tag ID.
For merchants in the Setup Wizard, you can find this within Step 4 (Tracking Code Installation).
For live merchants, you can find this by navigating to MY ACCOUNT > ACCOUNT DETAILS
Account Details: https://account.shareasale.com/m-account.cfm
If you cannot locate your Master Tag ID, or would like to verify that you have one, please submit a ticket to our ShareASale support staff.
<!-- Begin ShareASale Tracking -->
{%if first_time_accessed %}
<script>
const sasMid = 'XXXXX', sasStoreId = '', sasXtype = '', sasSkulist = [], sasPricelist = [], sasQuantitylist = [],
sasOrderName = '{{ order.name | handleize }}' || sasGetOrderRef(),
sasDiscounts = Shopify.checkout.discount ? parseFloat(Shopify.checkout.discount.amount) : 0,
sasCurrency = Shopify.checkout.presentment_currency || '{{ order.currency }}',
sasAmount = parseFloat(Shopify.checkout.subtotal_price),
sasDiscountPercent = 1 - (sasDiscounts / (sasAmount + sasDiscounts)),
sasNewCustomer = {% if customer.orders_count > 1 %}'0'{% elsif customer.orders_count <= 1 %} '1'{% else %} ''{% endif %},
sasCouponcode = Shopify.checkout.discount ? Shopify.checkout.discount.code : '',
sasVersion = 'shopify_4.0',
sasImg = new Image(),
sasMetaTagOpen = document.createElement('meta'),
sasMetaTagClose = document.createElement('meta');
sasMetaTagOpen.setAttribute('name', 'referrer'); sasMetaTagOpen.setAttribute('content', 'unsafe-url');
sasMetaTagClose.setAttribute('name', 'referrer'); sasMetaTagClose.setAttribute('content', 'origin');
Shopify.checkout.line_items.map((x) => {
sasSkulist.push(x.sku);
sasPricelist.push((x.price * sasDiscountPercent).toFixed(2));
sasQuantitylist.push(x.quantity)
});
sasImg.src = `https://shareasale.com/sale.cfm?v=${sasVersion}&merchantID=${sasMid}&transtype=sale&amount=${sasAmount}&tracking=${sasOrderName}&skulist=${sasSkulist}&pricelist=${sasPricelist}&quantitylist=${sasQuantitylist}¤cy=${sasCurrency}&couponcode=${sasCouponcode}&newcustomer=${sasNewCustomer}`;
if (sasStoreId) { sasImg.src += `&storeid=${sasStoreId}` }
if (sasXtype) { sasImg.src += `&xtype=${sasXtype}` }
document.body.appendChild(sasMetaTagOpen);
document.body.appendChild(sasImg);
document.body.appendChild(sasMetaTagClose);
function sasGetOrderRef() {
var orderRef;
try {
var orderLabel = document.querySelector('.os-order-number');
if (orderLabel !== null) {
orderRef = orderLabel.innerText.split('#')[1];
if (!orderRef) {
orderRef = orderLabel.innerText.split(' ')[1];
}
}
if (!orderRef) {
orderRef = window.Shopify.checkout.order_id;
}
if (!orderRef) {
throw Error('order_ref_error');
}
} catch (err) {
console.log('ShareASale: error getting orderRef from page. Using timestamp.');
orderRef = Date.now();
}
return orderRef;
}
</script>
{% endif %}
<script src="https://www.dwin1.com/!!!!!.js"></script>
Click Save in the bottom right corner of the page.
Master Tag Installation
Next you will need to install the Master Tag. In your Shopify store’s admin page, click the Online Store button in the sidebar. Under Themes in the side bar, find the Actions drop-down menu on the right. Choose Edit Code from the drop-down menu.
Find your Shopify theme’s theme.liquid template file, usually under the Layout section. Click its name to edit it.
Find the closing </head> HTML tag, place your cursor in front of it, and create a new line.
In the new line just created, copy and paste the following script code.
<script src="https://www.dwin1.com/!!!!!.js" type="text/javascript" defer="defer"></script>
Replace the !!!!!! in the code with your Master Tag ID.
For merchants in the Setup Wizard, you can find this within Step 4 (Tracking Code Installation).
For live merchants, you can find this by navigating to MY ACCOUNT > ACCOUNT DETAILS
Account Details: https://account.shareasale.com/m-account.cfm
If you cannot locate your Master Tag ID, or would like to verify that you have one, please submit a ticket to our ShareASale support staff.
Make sure you click Save in the top right corner of the page.
Testing
Now that your tracking tags have been installed, we will need to test that everything is working as expected. To do this, we’ll simulate an Affiliate referred purchase by clicking a ShareASale test link and then running a purchase on your store. If the test is successful we’ll see a record appear in your ShareASale console, which we will VOID so that it doesn’t debit commissions from your account.
If you were emailed a link to this document, a test link may have been provided to you. If it wasn’t, you can obtain one from your account by clicking here.
NOTE: If you do not click the test link your order will not track.
The test link should direct you to your own store. Once there, please purchase any item in your store. Sometimes Merchants will have a test item worth $1.00 sale price, but above $0.00 minimum.
After the purchase is complete, navigate to www.shareasale.com in your browser and log into your account. Click Reports and then click Transaction Details from the drop-down menu.
Filter the report for Affiliate ID 178 using the panel on the left. The filtered view should now show your test purchase as an entry with today’s date.
If the order tracked successfully…
Your account is now ready to use ShareASale with your store. Please contact us at ShareASale@ShareASale.com for further information about:
Product specific commissions (offer different commissions by product)
New customer incentives (offer commission bonuses for new customers)
Exclusive coupon codes (used for tracking conversions without link clickthrough)
If the order does not show up in the Transaction Details Report…
Please verify that you have completed all of the steps as instructed. Common mistakes include not entering the correct Merchant ID in your tracking code and forgetting to click the test link.
If after verifying all of these steps your tracking still does not work please contact our support team at ShareASale@ShareASale.com.
Copyright ShareASale 2021