Skip to content

Instantly share code, notes, and snippets.

@kmclaugh
Last active May 11, 2021 14:21
Show Gist options
  • Save kmclaugh/ef25dae51d2f3a2e796653d7545750f7 to your computer and use it in GitHub Desktop.
Save kmclaugh/ef25dae51d2f3a2e796653d7545750f7 to your computer and use it in GitHub Desktop.

These changes should be made the checkout process starting the https://winreality.com/cart/#payment page. They will let us track the checkout and purchase events accurately in google analytics, other tracking pixels.

The update to purchase-form.html will attach source information directly to purchases and thus customers.

Here's a video description.

/*
* action: check out step 1 "payment"
* description: fire on the "cart/#payment" ie the payment part of the checkout. we have a one step checkout.
* we'll use a seperate funnel for the members -> hitting -> payment funnel
* 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", // 1 // The checkout step
},
products: [
{
// the membership info:
id: "{{ product.id }}", // 'P12345' // use product id not variant id
name: "{{product.title}}", // 'Player/Parent, Coach/Academy'
quantity: "{{product.quantity}}", // 1
brand: "Win Reality",
price: '{{product.price}}', // 24.00 // make sure the price is a number ie 10.00 not $10.00
variant: "{{product.headset}}", // 'Baseball or Softball or Both'
// requires product-scoped custom dimensions:
role: "{{product.role}}", // 'Player/Parent, Coach/Academy'
},
{
// the hitting accessory is true:
id: "{{ product.id }}", // 'P12345' // use product id not variant id
name: "Hitting", // 'Hitting'
quantity: "{{product.quantity}}", // 1
brand: "Win Reality",
price: '{{product.price}}', // 24.00 // make sure the price is a number ie 10.00 not $10.00
// requires product-scoped custom dimensions:
role: "{{product.role}}", // 'Player/Parent, Coach/Academy'
},
],
},
},
});
<!-- Insert into the checkout form id="form-win" -->
<div class="hiddenFields" style="display: none">
<input id="clientId" />
<input id="gclid" />
<input id="source" />
<input id="medium" />
<input id="campaign" />
<input id="content" />
</div>
/*
* 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: "USD", // USD // the currency of the checkout
purchase: {
actionField: {
id: "{{checkout.order_number}}", // 12345 // The order number or transaction id
affiliation: "Win Reality",
revenue:
'{{checkout.total_price}}', // 24.00 // the total transaction value if annual use the annual amount $199
tax: '{{checkout.tax_price}}', // 1.0 // the tax paid
shipping:
'{{checkout.shipping_price}}', // 2.0 // cost of shipping
coupon: "{{discount.code}}", // SPRING // the discount code used
},
products: [
{
// the membership info:
id: "{{ product.id }}", // 'P12345' // use product id not variant id
name: "{{product.title}}", // 'Player/Parent, Coach/Academy'
quantity: "{{product.quantity}}", // 1
brand: "Win Reality",
price: '{{product.price}}', // 24.00 // make sure the price is a number ie 10.00 not $10.00
variant: "{{product.headset}}", // 'Baseball or Softball or Both'
// requires product-scoped custom dimensions:
role: "{{product.role}}", // 'Player/Parent, Coach/Academy'
},
{
// the hitting accessory is true:
id: "{{ product.id }}", // 'P12345' // use product id not variant id
name: "Hitting", // 'Hitting'
quantity: "{{product.quantity}}", // 1
brand: "Win Reality",
price: '{{product.price}}', // 24.00 // make sure the price is a number ie 10.00 not $10.00
// requires product-scoped custom dimensions:
role: "{{product.role}}", // 'Player/Parent, Coach/Academy'
},
],
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment