ROCKET ACADEMY

DASHBOARD

ACCOUNT

CONTACT

WEBINARS

LOGOUT

Lesson 5: EEC – Part 2 – Datalayer Variables

The second component of Enhanced Ecommerce is a Datalayer Variable, or DLV. We already covered variables in the previous lesson, and a DLV is no different than a standard variable, just that it gets it’s value from the datalayer. These are extremely easy to populate with GTM you simply need to tell GTM where the datalayer you want to capture exists.

Now there are two different type of datalayers in GTM – one is an object and the other is an array.

An object only has a single “layer” to it, in the sense that it will always be structured the same, regardless of what has been pushed.

An array, on the other hand can have a variety of objects to pull data from, depending on page data is view, and are typically found on top-level shop pages, cart pages and checkout actions when people are viewing or buying more than one item. So let’s take a look at how to isolate data from objects and from an array with the below datalayer.push.

dataLayer.push({
 
'event': 'purchase',
 
'ecommerce': {
     
'transaction_id': 'T12345',
     
'affiliation': 'Online Store',
     
'value': '59.89',
     
'tax': '4.90',
     
'shipping': '5.99',
     
'currency': 'EUR',
     
'coupon': 'SUMMER_SALE',
     
'items': [{
       
'item_name': 'Triblend Android T-Shirt',
       
'item_id': '12345',
       
'price': '15.25',
       
'item_brand': 'Google',
       
'item_category': 'Apparel',
       
'item_variant': 'Gray',
       
'quantity': 1
     
}, {
       
'item_name': 'Donut Friday Scented T-Shirt',
       
'item_id': '67890',
       
'price': '33.75',
       
'item_brand': 'Google',
       
'item_category': 'Apparel',
       
'item_variant': 'Black',
       
'quantity': 1
     
}]
 
}
});

To isolate the tax on this datalayer we would simply add  DLV Variable in GTM as such:

So there are two very simple things to undersstand here:

  1. The first word “ecommerce” tells GTM that is where to start looking.
  2. Using a period “.” indicates the is a 2nd layer of information, then putting the word tax indicates where to look on the 2nd layer for the data.

So this DLV would populate ‘4.90’ as the value, which you can then push into any environmen you want.

Now Let’s isolate an object within an array.

So there are three very simple things to undersstand here:

  1. As above we use the word “ecommerce” to tell GTM where to start looking, followed by a “.” to go down a level. 
  2. Then we select “items” to access the array. You know it is an array because it is followed by a square bracket “[” instead of a swiggley brracket. All arrays start and end with square brackets.
  3. Then we hit 0 to indicate that we want to select the first item within the array. All items in an array start with 0.
  4. Then we put “item_id” to retrieve that specific value.

So this DLV would populate ‘12345’ as the value, which you can then push into any environment you want.

If we wanted to retrieve the item_name ‘Donut Friday Scented T-Shirt’ from the second item we would use “ecommerce.items.1.item_name” for the Data Layer Variable Name. 

 

Tools in this Lesson

Lesson Assignment

No Assignment

Key Takeaways