Skip to content

Instantly share code, notes, and snippets.

@kmclaugh
Created October 28, 2021 16:28
Show Gist options
  • Save kmclaugh/f8c2799df5c0531d70cf9260912ce724 to your computer and use it in GitHub Desktop.
Save kmclaugh/f8c2799df5c0531d70cf9260912ce724 to your computer and use it in GitHub Desktop.
corpnet datalayer
/*
* action: purchase
* description: fire when the user actually completes the purchase
* required fields: actionField.id, actionField.revenue , product.id, product.name, product.quantity, product.price, product.variant (if applicable)
* reference: https://www.simoahava.com/analytics/enhanced-ecommerce-guide-for-google-tag-manager/#purchase
* exmplae url: https://www.corpnet.com/ssl/payment/payment/llc-tx/6fd0e0e40/
*/
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "purchase",
ecommerce: {
currencyCode: "USD",
purchase: {
actionField: {
id: "{{purchase.order_number}}", // 123456 // Corpnet Order Number
affiliation: "CorpNet",
revenue: '{{purchase.total_price}}', // 487.00 // the total transaction value
shipping: '{{purchase.shipping_and_handling}}', // 29.00 // shipping and handling
tax: '{{purchase.total_tax}}', // 2.0 // total taxes for the order
stateFee: '{{purchase.stateFee}}', // 310 // total state fee for the order
coupon: "{{discount.code}}", // SUMMER2020 // the discount code used
},
products: [
{
// built-in enhanced ecommerce fields:
id: "{{ product.id }}", // 'P12345' // use product id not variant id
name: "{{product.title}}", // 'business formation'
quantity: "{{product.quantity}}", // 1 //
brand: "CorpNet",
price: '{{product.price}}', // 79.0 // the individual products price
variant: "{{product.selected_variant.variant.name}}", // llc // structure
state: "{{product.state}}", // texas // max five levels of hierarchy
},
],
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment