Collect Enhanced Ecommerce Values into GTM Variables

Setting up Enhanced Ecommerce tracking via Google Tag Manager & Google Analytics generally involves creating a data layer that contains all the relevant values, as described here: https://developers.google.com/tag-manager/enhanced-ecommerce#purchases

These same values are often required to set up other marketing and analytics tags. For example, the Facebook conversion pixel looks like this:

If you wanted to use Google Tag Manager to substitute in the actual conversion amount where it reads 30.00, you can grab that value from the Enhanced Ecommerce data layer, push it into a Variable, and then replace that fixed value with a dynamic variable, like this:

This post will show how to retrieve all the values from the Enhanced Ecommerce data layer into GTM Data Layer Variables, where they can be re-used.

NEW! API CONNECTOR ADD-ON FOR GOOGLE SHEETS

Check out my new API Connector Add-on to import data from thousands of platforms (e.g. Shopify, Harvest, Mailchimp, ActiveCampaign, VWO, YouTube, etc.) directly into Google Sheets.

DATA LAYER VARIABLE SETUP

Note that this requires that you have already set up your Enhanced Ecommerce data layer on the transaction page. 

To create a Data Layer variable, navigate in GTM to Variables > User-Defined Variables > New > Data Layer Variable, and fill in the appropriate Data Layer Variable Name, as listed below. This screenshot shows an example of what the completed Variable will look like:

enhanced-ecommerce-values-img1

ENHANCED ECOMMERCE DATA LAYER VARIABLE NAMES

  1. Transaction Revenue
    ecommerce.purchase.actionField.revenue
  2. Transaction ID
    ecommerce.purchase.actionField.id
  3. Transaction Affiliation
    ecommerce.purchase.actionField.affiliation
  4. Transaction Tax
    ecommerce.purchase.actionField.tax
  5. Transaction Shipping
    ecommerce.purchase.actionField.shipping
  6. Transaction Coupon
    ecommerce.purchase.actionField.shipping
  7. Transaction Currency
    ecommerce.currencyCode

DATA LAYER PRODUCT INFO

The above can be simply accessed via data layer variables because they are all transaction-level information, with just a single value per transaction. It’s a little more complicated to retrieve product-level information because a single order contains multiple products. If you want to get product information, you’ll need to create a custom JavaScript variable by navigating in GTM to Variables > User-Defined Variables > New > Custom JavaScript Variable.

Below is an example setup for how to get a comma-separated list of SKUs out of your enhanced ecommerce data layer:

  1. Create a Data Layer Variable to contain the entire ecommerce object:
    enhanced-ecommerce-values-img2
  2. Create a custom JS variable that extracts the information you need from the above ‘DL – Ecommerce’ Variable.
 

This script would produce a Variable like this: 12345,67890,12345

The above script could be modified to return a list of product names, prices, or anything else contained within the itemized portion of the Enhanced Ecommerce data layer push. Any specific requests? Please comment below.

Comments:2

  1. Thank you so much for this post! This was EXACTLY what I was looking to do with GTM for Facebook Pixel tracking so you nailed it!

Leave a Reply

Your email address will not be published.