I’m trying to create a dataLayer variable so I can push the product name into the event label.
The dataLayer push when a user adds a product to cart is:
{
event: "addToCart",
gtm: {
uniqueEventId: 107,
start: 1666871102469,
scrollThreshold: 75,
scrollUnits: "percent",
scrollDirection: "vertical",
triggers: "30151582_46"
},
customer_id: "4cfa14bf-1749-47a3-9063-e19c0bc6f3a8",
ecommerce: {
currencyCode: "NZD",
add: {
products: [
{
name: "Panadol Rapid Soluble Tablets - Packet 20",
id: "FAH262",
price: 12.28,
brand: "Panadol",
category: "Web / Dental / Consumables / Anaesthetics / Pain" +
" Relief",
variant: "",
quantity: 1
}
]
}
}
}
I’ve tried to create a dataLayer variable with the following
ecommerce.add.products[0].name
This is returning undefined in preview mode when I do test add to carts.
Where am I going wrong?
Advertisement
Answer
You might need to change the DataLayer variable to
I can’t really remember where I saw about this.
But when fetching data through here.
It is not regular get products[0].name but products.0.name
