Last active
March 30, 2023 14:45
-
-
Save jrosell/85e3bfeab376b97d5e4738d7aaafc5ee to your computer and use it in GitHub Desktop.
Google Tag Manager examples for ecommerce tracking on GA4. More info: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm
This file contains 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
// View item: It should be executed when the product detail is shown. | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "view_item", | |
ecommerce: { | |
currency: "USD", | |
value: 7.77, | |
items: [ | |
{ | |
item_id: "SKU_12345", | |
item_name: "Stan and Friends Tee", | |
affiliation: "Google Merchandise Store", | |
coupon: "SUMMER_FUN", | |
discount: 2.22, | |
index: 0, | |
item_brand: "Google", | |
item_category: "Apparel", | |
item_category2: "Adult", | |
item_category3: "Shirts", | |
item_category4: "Crew", | |
item_category5: "Short sleeve", | |
item_list_id: "related_products", | |
item_list_name: "Related Products", | |
item_variant: "green", | |
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", | |
price: 9.99, | |
quantity: 1 | |
} | |
] | |
} | |
}); | |
// Add to cart: It should fire when the user click the buton with the intention to purchase the product. | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "add_to_cart", | |
ecommerce: { | |
currency: "USD", | |
value: 7.77, | |
items: [ | |
{ | |
item_id: "SKU_12345", | |
item_name: "Stan and Friends Tee", | |
affiliation: "Google Merchandise Store", | |
coupon: "SUMMER_FUN", | |
discount: 2.22, | |
index: 0, | |
item_brand: "Google", | |
item_category: "Apparel", | |
item_category2: "Adult", | |
item_category3: "Shirts", | |
item_category4: "Crew", | |
item_category5: "Short sleeve", | |
item_list_id: "related_products", | |
item_list_name: "Related Products", | |
item_variant: "green", | |
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", | |
price: 9.99, | |
quantity: 1 | |
} | |
] | |
} | |
}); | |
// Begin checkout: It should fire as the first step in the checkout process (registered and logged or purchase as guest, if available) | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "begin_checkout", | |
ecommerce: { | |
currency: "USD", | |
value: 7.77, | |
coupon: "SUMMER_FUN", | |
items: [ | |
{ | |
item_id: "SKU_12345", | |
item_name: "Stan and Friends Tee", | |
affiliation: "Google Merchandise Store", | |
coupon: "SUMMER_FUN", | |
discount: 2.22, | |
index: 0, | |
item_brand: "Google", | |
item_category: "Apparel", | |
item_category2: "Adult", | |
item_category3: "Shirts", | |
item_category4: "Crew", | |
item_category5: "Short sleeve", | |
item_list_id: "related_products", | |
item_list_name: "Related Products", | |
item_variant: "green", | |
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", | |
price: 9.99, | |
quantity: 1 | |
} | |
] | |
} | |
}); | |
// Payment information submitted: It should fire when payment method information is entered by the user (optional: only if appropiate). | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "add_payment_info", | |
ecommerce: { | |
currency: "USD", | |
value: 7.77, | |
coupon: "SUMMER_FUN", | |
payment_type: "Credit Card", | |
items: [ | |
{ | |
item_id: "SKU_12345", | |
item_name: "Stan and Friends Tee", | |
affiliation: "Google Merchandise Store", | |
coupon: "SUMMER_FUN", | |
discount: 2.22, | |
index: 0, | |
item_brand: "Google", | |
item_category: "Apparel", | |
item_category2: "Adult", | |
item_category3: "Shirts", | |
item_category4: "Crew", | |
item_category5: "Short sleeve", | |
item_list_id: "related_products", | |
item_list_name: "Related Products", | |
item_variant: "green", | |
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", | |
price: 9.99, | |
quantity: 1 | |
} | |
] | |
} | |
}); | |
// Purchase: It should fire at the confirmation page when user have completed the transatction and paid the purchase succefully. | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "purchase", | |
ecommerce: { | |
transaction_id: "T_12345", | |
value: 25.42, | |
tax: 4.90, | |
shipping: 5.99, | |
currency: "USD", | |
coupon: "SUMMER_SALE", | |
items: [ | |
{ | |
item_id: "SKU_12345", | |
item_name: "Stan and Friends Tee", | |
affiliation: "Google Merchandise Store", | |
coupon: "SUMMER_FUN", | |
discount: 2.22, | |
index: 0, | |
item_brand: "Google", | |
item_category: "Apparel", | |
item_category2: "Adult", | |
item_category3: "Shirts", | |
item_category4: "Crew", | |
item_category5: "Short sleeve", | |
item_list_id: "related_products", | |
item_list_name: "Related Products", | |
item_variant: "green", | |
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", | |
price: 9.99, | |
quantity: 1 | |
}, | |
{ | |
item_id: "SKU_12346", | |
item_name: "Google Grey Women's Tee", | |
affiliation: "Google Merchandise Store", | |
coupon: "SUMMER_FUN", | |
discount: 3.33, | |
index: 1, | |
item_brand: "Google", | |
item_category: "Apparel", | |
item_category2: "Adult", | |
item_category3: "Shirts", | |
item_category4: "Crew", | |
item_category5: "Short sleeve", | |
item_list_id: "related_products", | |
item_list_name: "Related Products", | |
item_variant: "gray", | |
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo", | |
price: 20.99, | |
promotion_id: "P_12345", | |
promotion_name: "Summer Sale", | |
quantity: 1 | |
}] | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment