Enhanced eCommerce

This sandbox will let you test out your Google Tag Manager knowledge in a safe place, without having to constnatly set up your own testing environments. Or, worse, doing it live.

Show / Hide Demo Code


We want to track completed purchases into Google Analytics using the Enhanced eCommerce structure.

In most cases a purchase occurs on a separate page rather than as an AJAX event, but both are possible options. One a completed purchase...

  1. AJAX: If the URL stays the same, ask the developer to fire a dataLayer event using the success callback function. For demo purposes, this is what you'd wrap around your code on this sandbox website to do that:

    document.addEventListener('dg.success',
    	function() {
    		...
    });
    
  2. Thank You Page: If the URL changes, we would ask the developer to fire a dataLayer event on page load on the thank you page.
# Product Price
3 Pen, Blue $1.50
1 Banana $0.50
2 Jellybean $0.10
Coupon (COOLYYZ) -$5.00
Delivery $5.00
Subtotal $5.20
Tax (13%) $0.65
Total $5.85

We want to push transaction data into the dataLayer so that we can track it across various marketing platforms.

Refer to this document for addtional guidance around the dataLayer code: Simo Ahava's eCommerce Guide for Google Tag Manager

Acceptance Criteria:

  • The dataLayer code provided below is fired on a successful purchase.
  • The values must all be replaced with real values.
					dataLayer.push({
	'event': 'eec.purchase',
	'ecommerce': {
		'currencyCode': 'CAD',
		'purchase': {
			'actionField': {
				'id': 'olkij-adsasd-asds',
				'revenue': '11.53',
				'tax':'1.33',
				'shipping': '5.00',
				'coupon': 'COOLYYZ'
			},
			'products': [
			{
				'name': 'Pen',
				'id': 'DG-918974',
				'price': '1.50',
				'brand': 'Delta Growth',
				'category': 'Stationery/Pens',
				'variant': 'Blue',
				'quantity': 3,
				'coupon': 'COOLYYZ'
			 },
			 {
				'name': 'Banana',
				'id': 'DG-895726',
				'price': '0.50',
				'brand': 'Delta Growth',
				'category': 'Grocery/Fruit',
				'quantity': 1,
				'coupon': 'COOLYYZ'
			 },
			 {
				'name': 'Jellybean',
				'id': 'DG-814346',
				'price': '0.10',
				'brand': 'Delta Growth',
				'category': 'Grocery/Snacks',
				'quantity': 2,
				'coupon': 'COOLYYZ'
			 },
			]
		}
	}
});
				

AJAX and Thank You page style form submissions differ somewhat in tracking. AJAX forms don't change the URL on submission, while Thank You page style forms do. These are tracked differently and widely depend on your CMS and plugins.

Note: When we're tracking form submissions what we really want to track is a successful action. If a user tries to submit a contact form, etc and it fails for some reason, we don't want to track it.

AJAX Style

					document
.addEventListener('dg.success', function() {
	dataLayer.push({
		'event': 'eec.purchase',
		'ecommerce': {
			'currencyCode': 'CAD',
			'purchase': {
				'actionField': {
					'id': 'olkij-adsasd-asds',
					'revenue': '11.53',
					'tax':'1.33',
					'shipping': '5.00',
					'coupon': 'COOLYYZ'
				},
				'products': [
				{
					'name': 'Pen',
					'id': 'DG-918974',
					'price': '1.50',
					'brand': 'Delta Growth',
					'category': 'Stationery/Pens',
					'variant': 'Blue',
					'quantity': 3,
					'coupon': 'COOLYYZ'
				 },
				 {
					'name': 'Banana',
					'id': 'DG-895726',
					'price': '0.50',
					'brand': 'Delta Growth',
					'category': 'Grocery/Fruit',
					'quantity': 1,
					'coupon': 'COOLYYZ'
				 },
				 {
					'name': 'Jellybean',
					'id': 'DG-814346',
					'price': '0.10',
					'brand': 'Delta Growth',
					'category': 'Grocery/Snacks',
					'quantity': 2,
					'coupon': 'COOLYYZ'
				 },
				]
			}
		}
	});
});
			

Or, Code to Add to Thank You Page

				dataLayer.push({
	'event': 'eec.purchase',
	'ecommerce': {
		'currencyCode': 'CAD',
		'purchase': {
			'actionField': {
				'id': 'olkij-adsasd-asds',
				'revenue': '11.53',
				'tax':'1.33',
				'shipping': '5.00',
				'coupon': 'COOLYYZ'
			},
			'products': [
			{
				'name': 'Pen',
				'id': 'DG-918974',
				'price': '1.50',
				'brand': 'Delta Growth',
				'category': 'Stationery/Pens',
				'variant': 'Blue',
				'quantity': 3,
				'coupon': 'COOLYYZ'
			 },
			 {
				'name': 'Banana',
				'id': 'DG-895726',
				'price': '0.50',
				'brand': 'Delta Growth',
				'category': 'Grocery/Fruit',
				'quantity': 1,
				'coupon': 'COOLYYZ'
			 },
			 {
				'name': 'Jellybean',
				'id': 'DG-814346',
				'price': '0.10',
				'brand': 'Delta Growth',
				'category': 'Grocery/Snacks',
				'quantity': 2,
				'coupon': 'COOLYYZ'
			 },
			]
		}
	}
});
			

This site is sandbox environment that initiates your GTM container and sends data to your connected platforms. Use a GTM container and connected platforms that you're comfortable passing demo data to.