#GTMTips: Access Array Members In The Data Layer
simo, you'd use something like:
var firstValue = simo;
In Google Tag Manager, you can push Arrays into the Data Layer. However, the Data Layer Variable type, which you use to retrieve values stored in the Data Layer, does not support the aforementioned square bracket notation in its fields. Instead, you need to use a special, proprietary format to access Array members.
Tip 28: Use dot notation to access Array members in the Data Layer
Array.0.name in Google Tag Manager.
Do note that this also means that you can't use square bracket notation to access object literal properties either. You need to use dot notation all the way through.
A practical example is in Ecommerce tracking. To get the SKU of the first product in an
ecommerce.purchase object (Enhanced Ecommerce), you'd use this in a Data Layer Variable:
That retrieves the value stored in the
id key of the first product in the
products Array of the Enhanced Ecommerce