Google Analytics ecommerce

Use Tag Manager to implement Google Analytics ecommerce tags.

There are two main types of Google Analytics ecommerce implementation methods: Standard ecommerce and enhanced ecommerce.

Standard ecommerce reports in Google Analytics allow you to track transactions and 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 additional functionality to your Google Analytics standard ecommerce 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.

These instructions describe how to use Google Tag Manager to implement Google Analytics ecommerce tags.

Standard Ecommerce

To set up a standard Google Analytics ecommerce tag:

  1. Login to your Google Analytics Account and enable ecommerce for the view your want.
  2. Create a Universal Analytics tag and set the Track Type to Transaction.
  3. Configure your tag with the required fields.
  4. Add the dataLayer() object to the transaction page to collect and pass the required variables. Make sure the dataLayer() variables are populated in code before the tag fires.
  5. Create a trigger to fire the tag on the transaction confirmation page.

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': 'Hat',
       '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 that are used to implement enhanced ecommerce with Tag Manager:

  • Data layer: The preferred method; push ecommerce data to the data layer from your code.
  • Custom JavaScript variable: 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.

With either method, you should first become familiar with enhanced ecommerce in the Google Analytics before you use Tag Manager to implement enhanced ecommerce tags. You may need to enlist the help of a developer for your data layer implementation.

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 with these additional settings:
    • Set the Track Type to either Page View or Event.
    • In the Google Analytics Settings variable, under More Settings and then Ecommerce, set Enable Enhanced Ecommerce Features to True.
    • Select Use Data Layer.

Custom JavaScript variable implementation

  1. Create a Custom JavaScript variable. This variable must return an object that contains the ecommerce object, similar to this code example:
     
    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.
  2. In Tag Manager, create a Universal Analytics tag with these additional settings:
    • Set the Track Type to either Page View or Event.
    • In the Google Analytics Settings variable, under More Settings and then Advertising, set Enable Enhanced Ecommerce Features to True.
    • Select Use Data Layer.

Related resources

Was this article helpful?
How can we improve it?