Big Commerce Tracking Script Implementation
In order to use this implementation method, your BigCommerce store must use Stencil themes.
- Log in to your BigCommerce Store
- In the side navigation menu navigate to Storefront > Script Manager and then click Create a Script.
- Complete the Edit Script page with the following information:
- Name of script = AvantLink Tracking
- Description = Script used to track affiliate orders.
- Location on page = Footer
- Select pages where script will be added = All pages
- Script Category = Analytics
- Script type = Script
- Script components = Paste the script AvantLink supplied in the welcome email or revise the script template included in this article to use your site id.
Big Commerce Tracking Script Template
This script was attached in your technical integration welcome email. If you do not have it, you can use the template below.
- Copy the template below and paste it somewhere you can edit it.
- On the line, 'cdn.avmws.com/SITE_ID/'
- Delete the "SITE_ID" placeholder and enter your actual site id. Leave no spaces between the site id and backslashes.
- Your site id is your five digit merchant id prepended with the number 10.
- For example, if your merchant id is 10048, your site id would be: 1010048.
<script type="text/javascript">
var _AvantMetrics = _AvantMetrics || [];
(async function() {
if ('{{checkout.order.id}}') {
await buildAvMetrics();
}
var avm = document.createElement('script');
avm.type = 'text/javascript'; avm.async = true;
avm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.avmws.com/SITE_ID/';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(avm, s);
console.log(_AvantMetrics);
})();
async function setOrderData() {
var order = await getData('/api/storefront/order/{{checkout.order.id}}');
return order;
}
async function getData(url = '') {
var res = '';
if(url !== ''){
const response = await fetch(url, {
credentials: 'include'
});
res = response.json();
}
return res;
}
async function buildAvMetrics() {
let orderData = await setOrderData();
window._AvantMetrics.push(['order', { order_id: orderData.orderId, amount: orderData.orderAmount - orderData.taxTotal - orderData.shippingCostTotal, state: orderData.billingAddress.stateOrProvinceCode, country: orderData.billingAddress.countryCode, ecc: orderData.coupons.length > 0 ? orderData.coupons[0].code: '', tax: orderData.taxTotal, currency: orderData.currency.code, new_customer: orderData.customerId ? 'N' : 'Y' }]);
for (line of orderData.lineItems.physicalItems) {
window._AvantMetrics.push(['item', { order_id: orderData.orderId, variant_sku: line.sku, price: line.salePrice, qty: line.quantity }]);
}
for (line of orderData.lineItems.digitalItems) {
window._AvantMetrics.push(['item', { order_id: orderData.orderId, variant_sku: line.sku, price: line.salePrice, qty: line.quantity }]);
}
}
</script>