Created
October 30, 2020 19:50
-
-
Save jmlagace/c1efd114f6e359063ea6e5a9914610cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* track the sale in GTM */ | |
$(document).on(`page:load page:change`, function() { | |
try { | |
if (Shopify.checkout && Shopify.Checkout.page == 'thank_you') { | |
dataLayer.push({ | |
'event': 'eec.purchase', | |
'ecommerce': { | |
'currencyCode': Shopify.checkout.currency, | |
'purchase': { | |
'actionField': { | |
'id': Shopify.checkout.order_id, | |
'revenue': Shopify.checkout.total_price, | |
'tax': Shopify.checkout.total_tax, | |
'shipping': Shopify.checkout.shipping_rate.price, | |
'coupon': (Shopify.checkout.discount ? Shopify.checkout.discount.code : ''), | |
'discount': (Shopify.checkout.discount ? Shopify.checkout.discount.amount : '') | |
}, | |
'products': Shopify.checkout.line_items.map(function(item) { | |
return { | |
'name': item.title, | |
'id': item.variant_id, | |
'price': item.price, | |
'brand': item.vendor, | |
'category': '', | |
'variant': item.variant, | |
'quantity': item.quantity, | |
'coupon': '' | |
}; | |
}) | |
} | |
} | |
}); | |
} | |
} catch(err) { | |
console.log(err); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment