Google Analytics for E-commerce

Using GTM (Google Tags Manager)

Add a “Google Analytics” tag and choose the “Track Type” of Transaction. All the transaction information should be passed via the data layer.

Variable Name Description Type
transactionId (Required) Unique transaction identifier string
transactionAffiliation (Optional) Partner or store string
transactionTotal (Required) Total value of the transaction numeric
transactionShipping (Optional) Shipping charge for the transaction numeric
transactionTax (Optional) Tax amount for the transaction numeric
transactionProducts (Optional) List of items purchased in the transaction array of TransactionProduct objects

TransactionProduct Data

Variable Name Description Type
name (Required) Product name string
sku (Required) Product SKU string
category (Optional) Product category string
price (Required) Unit price numeric
quantity (Required) Number of items numeric

Here's an example of how this would look:

	<script>
	dataLayer = [{
	    'transactionId': '1234',
	    'transactionAffiliation': 'Acme Clothing',
	    'transactionTotal': 38.26,
	    'transactionTax': 1.29,
	    'transactionShipping': 5,
	    'transactionProducts': [{
	        'sku': 'DD44',
	        'name': 'T-Shirt',
	        'category': 'Apparel',
	        'price': 11.99,
	        'quantity': 1
	    },{
	        'sku': 'AA1243544',
	        'name': 'Socks',
	        'category': 'Apparel',
	        'price': 9.99,
	        'quantity': 2
	    }]
	}];
	</script>

Place this code before the Google Tag Manager container snippet so that the dataLayer is ready when Google Tag Manager fires the Google Analytics tag asynchronously.

 

If you can’t do this and your data layer is placed below the Google Tag Manager code on the page, add a condition to your rule to wait until the page (DOM) is fully loaded, with the built-in event “gtm.dom”:

If you opt to have the tag fired based on a custom event, you can combine the data and the event push as described in the developer documentation: https://developers.google.com/tag-manager/devguide#multipush 

For another great article about using google tag manger with Ecommerce, go to This guide