Below is the code that needs to be added when the user
- Adds a giftcard to the cart
- Begins checkout
- Completes the purchase of the giftcard
The {{variable}}
templates need to be filled in with the actual values.
/* | |
* action: add to cart | |
* description: fire whenever a user adds the giftcard to the cart. | |
* required fields: product.id and product.name | |
* reference: https://www.simoahava.com/analytics/enhanced-ecommerce-guide-for-google-tag-manager/#add-to-cart | |
* notes: the products list should include ONLY the product that was added to the cart, not the entire cart | |
*/ | |
window.dataLayer = window.dataLayer || []; | |
window.dataLayer.push({ | |
event: "eec.add", | |
eecEventName: "Add to Cart", | |
ecommerce: { | |
add: { | |
actionField: { | |
list: "cart", // | |
}, | |
products: [ | |
{ | |
// built-in enhanced ecommerce fields: | |
id: "gift_card", | |
name: "Gift Card", | |
quantity: "{{product.quantity}}", // 1 // the quantity of cards purchased | |
brand: "RA Sushi", | |
price: '{{amount}}', // the amount of the giftcard | |
variant: "{{card_type}}", // ecard or plastic | |
}, | |
], | |
}, | |
}, | |
}); |
/* | |
* action: check out | |
* description: fire when the user begins the checkout process | |
* required fields: actionField.step, product.id and product.name | |
* reference: https://www.simoahava.com/analytics/enhanced-ecommerce-guide-for-google-tag-manager/#checkout | |
*/ | |
window.dataLayer = window.dataLayer || []; | |
window.dataLayer.push({ | |
event: "eec.checkout", | |
eecEventName: "Checkout 1", | |
ecommerce: { | |
checkout: { | |
actionField: { | |
step: "1" | |
}, | |
products: [ | |
{ | |
// built-in enhanced ecommerce fields: | |
id: "gift_card", | |
name: "Gift Card", | |
quantity: "{{product.quantity}}", // 1 // the quantity of cards purchased | |
brand: "RA Sushi", | |
price: '{{amount}}', // the amount of the giftcard | |
variant: "{{card_type}}", // ecard or plastic | |
}, | |
], | |
}, | |
}, | |
}); |
/* | |
* 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 | |
*/ | |
window.dataLayer = window.dataLayer || []; | |
window.dataLayer.push({ | |
event: "eec.purchase", | |
eecEventName: "Purchase", | |
ecommerce: { | |
currencyCode: "{{checkout.current_code}}", // USD // the currency of the checkout | |
purchase: { | |
actionField: { | |
id: "{{checkout.order_number}}", // 12345 // The order number or transaction id | |
affiliation: "wgiftcard", // my shop // Where the order took place (ie your store) | |
revenue: | |
'{{total_price}}', // 11.00 // the total transaction value | |
tax: '0', // 1.0 // the tax paid | |
shipping: '{{shipping_cost}}', // 2.0 // cost of shipping | |
}, | |
products: [ | |
{ | |
// built-in enhanced ecommerce fields: | |
id: "gift_card", | |
name: "Gift Card", | |
quantity: "{{product.quantity}}", // 1 // the quantity of cards purchased | |
brand: "RA Sushi", | |
price: '{{amount}}', // the amount of each giftcards | |
variant: "{{card_type}}", // ecard or plastic | |
}, | |
], | |
}, | |
}, | |
}); |