JavaScript Conversion Tracking for Shopify

Implementing Affiliate Tracking is Easy with Shopify

The Shopify App makes it simple to set up tracking. Our system allows you to track and manage sales and activity from all FlexOffers affiliate partners (also known as publishers, influencers, and bloggers). The app is the only Shopify store integration required, and it gives you complete access to the FlexOffers tracking platform, where you can manage publishers in detail and advertise various programs, products, and services.

To continue, you must first create a FlexOffers account (click here to apply). You'll receive an 'Advertiser ID' from your account, which you'll need to set up the Shopify app. Your FlexOffers account has a profile page dedicated to your company, where you can choose the commission you want to pay publishers and access all of the features and controls you need to expand your program to its greatest potential.

Step-by-step instructions on how to accomplish it manually can be found below.

Homepage Footer Implementation:

1) On the dashboard, click on Sales Channels and select Themes. 

2) Under Current Theme, click on Actions, open the dropdown menu and select Edit Code.

3) From the Layout menu, click on {/} theme.liquid.

4) Scroll to the bottom, find </body>

5) Enter the script below before the tag.

<script>
!function(){var e=window.flextrack=window.flextrack||[];if(e.invoked)window.console&&console.error&&console.error("FlexOffers library was included more than once.");else{e.invoked=!0,e.methods=["init","getClick","track"],e.factory=function(r){return function(){var t=Array.prototype.slice.call(arguments);return t.unshift(r),e.push(t),e}};for(var r=0;r<e.methods.length;r++){var t=e.methods[r];e[t]=e.factory(t)}e.init=function(r){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=”https://advertiserpro.flexoffers.com/vendors/flexoffers/flexoffers.tracking.lib.js”;var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n),e.advertiserId=r}}}()

flextrack.init("Unique Advertiser ID");
flextrack.getClick();
</script>

6) Click on Save button on top right.

Order Confirmation Page Implementation:

1) On the dashboard, click on Settings button at the bottom.

2) Select Checkout.

3) Under Order Processing section, find Additional Script

4) Find your unique Advertiser ID in your FlexOffers User Interface.

  • Your advertiserid should follow a similar format as this: 12345678-1234-1234-1234-12345678912 (example).
  • Copy your advertiserid.

5) Paste your advertiserid onto the following script where it says [ADD_YOUR_AID_HERE].

 

<script>
!function(){var e=window.flextrack=window.flextrack||[];if(e.invoked)window.console&&console.error&&console.error("FlexOffers library was included more than once.");else{e.invoked=!0,e.methods=["init","getClick","track"],e.factory=function(r){return function(){var t=Array.prototype.slice.call(arguments);return t.unshift(r),e.push(t),e}};for(var r=0;r<e.methods.length;r++){var t=e.methods[r];e[t]=e.factory(t)}e.init=function(r){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=”https://advertiserpro.flexoffers.com/vendors/flexoffers/flexoffers.tracking.lib.js”;var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n),e.advertiserId=r}}}()
flextrack.init("Unique Advertiser Tracking ID");

var checkoutDetails = window.Shopify.checkout;
var order_nummber_tag = window.document.getElementsByClassName(
"os-order-number"
);
const orderNumber =
order_nummber_tag && order_nummber_tag[0] && order_nummber_tag[0].innerText ?
`${order_nummber_tag[0].innerText.split("#")[1]}` :
"";
window.Shopify.checkout &&
window.Shopify.checkout["order_id"] &&
flextrack.track({
order_number: orderNumber,
order_amount: checkoutDetails.subtotal_price,
order_coupon: checkoutDetails &&
checkoutDetails.discount &&
checkoutDetails.discount.code ?
checkoutDetails.discount.code :
"",
order_items: checkoutDetails && checkoutDetails.line_items ?
checkoutDetails.line_items.map((c) => {
const {
discount_allocations,
price,
quantity,
sku
} = c;
const amount =
discount_allocations &&
discount_allocations.length &&
discount_allocations[0].amount ?
price - discount_allocations[0].amount :
price;
return {
sku: sku ? sku : "MISC",
amount: amount,
quantity: quantity ? quantity : 0,
};
}) :
[],
}); </script>

7) Click on Save button down the bottom right.6) Copy the entire script and paste it onto the Additional Script box on the Shopify platform.


**DISCLAIMER: Shopify parameters provided above for Order Amount and Order ID have worked with previous accounts in the past; however, FlexOffers cannot guarantee that these are still current. If your conversion tracking fails, we encourage you to contact Shopify directly to make sure you have the correct parameter supported by your website.

Articles in this section