Google Analytics ecommerce

There are two main types of of Google Analytics ecommerce implementation methods:

Standard ecommerce reports in Google Analytics allow you to analyze purchase activity on your site or app. You can see product and transaction information, average order value, ecommerce conversion rate, time to purchase, and other data.

Enhanced ecommerce adds functionality to your Google Analytics reports. Enhanced ecommerce shows when customers added items to their shopping carts, when they started the checkout process, and when they completed a purchase. You can also use enhanced ecommerce to identify segments of customers who fall out of the shopping funnel.

Both methods can be implemented with Tag Manager:

Standard Ecommerce

To set up a standard Google Analytics ecommerce tag:

  1. Enable ecommerce in your Google Analytics reports.
  2. Create a Universal Analytics tag and set the Track Type to Transaction.
  3. Configure your tag with the required fields.
  4. Specify when the tag should be triggered.

All the transaction information should be passed via the data layer, with the variable names shown below:

Transaction Data

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 product objects

Product 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 the data layer code might be implemented in JavaScript:

<script>
window.dataLayer = window.dataLayer || []
dataLayer.push({
   '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 above the Tag Manager container snippet so that the data layer is ready when Tag Manager fires the Google Analytics tag.

If for some reason you can’t place the ecommerce data above the Tag Manager container snippet, you can try one of these solutions:

  • Have the tag fire based on a custom event farther down the page (e.g. combine the data and the event push as described in the developer documentation.)
  • Set the Trigger type to “DOM Ready”.

Learn more about Google Analytics ecommerce.

Enhanced Ecommerce

There are two methods for implementing enhanced ecommerce using Tag Manager:

  • Data layer: The preferred method; push ecommerce data to the data layer from your code.
  • Custom JavaScript: Create a Custom JavaScript variable in Tag Manager. This variable should return an object with the information that you would otherwise push onto the data layer.

Important: There are several specific types of information that are available to work with in enhanced ecommerce implementations. Please refer to the developer documentation for a complete list of data types that are supported.

Data layer implementation

  1. In your code, add the ecommerce information to a data layer object called "ecommerce". Refer to the Tag Manager developer documentation for details on how to implement a data layer.
  2. In Tag Manager, create a Universal Analytics tag and set the Track Type to either Page View or Event.
  3. Under More Settings and then Advertising, set Enable Enhanced Ecommerce Features to True
  4. Select Use Data Layer.

Using a Variable

  1. Create a Custom JavaScript variable. This variable must return an object that contains the ecommerce object, similar to the code example below:
     
    function() {
     var ecommerceData = {
       'ecommerce' : {
         currencyCode : 'EUR',
         // add additional parameters as needed...
       }
     };
     return ecommerceData;
    }
    			
    In this variable, use the same syntax that would be used to push this data onto the data layer. Refer to the developer documentation for more information.
  2. Create a Universal Analytics tag and set the Track Type to either Page View or Event.
  3. Under More Settings and then Advertising, set Enable Enhanced Ecommerce Features to True
  4. Select Use Data Layer.

Related resources

Was this article helpful?
How can we improve it?