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.
'affiliation': 'Online Store',
'item_name': 'Triblend Android T-Shirt',
'item_name': 'Donut Friday Scented T-Shirt',
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:
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:
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.