-
Extracting Ecommerce Purchase Item Names for GTM Marketing Tag
I’m currently trying to extract only the “item_name” data from my purchase dataLayer. I’m using the dataLayer variable, but it doesn’t seem to be working. Since “ecommerce.items” renders the entire item info, I’ve attempted to create a JavaScript Variable in Google Tag Manager. However, I’m still getting an array of values instead of the comma-separated text list that I need. So, how can I convert this array into a text format? Here’s what the JavaScript Variable looks like in GTM:
`
var itemslist = [];
var products = {{dl – ecommerce – item name}};
for(i=0; i < products.length; i++){
itemlist.push(
'item_name': products[i].item_name
)
}
return itemlist;
`
I’m using the “ecommerce.items” as the dataLayer variable in GTM. Here’s an example of my complete dataLayer:
`
{
“event”: “purchase”,
“ecommerce”: {
“transaction_id”: 0000,
“affiliation”: “xxxx”,
“value”: 222,
“currency”: “USD”,
“coupon”: “No coupon”,
“items”: [
{
“item_id”: “4291”,
“item_name”: “xyz”,
“affiliation”: “xxx”,
“coupon”: “No coupon”,
“item_category”: “us”,
“currency”: “USD”,
“discount”: “0.00”,
“index”: 0,
“price”: 111,
“quantity”: 1
},
{
“item_id”: “xxx”,
“item_name”: “abc”,
“affiliation”: “xxx”,
“coupon”: “No coupon”,
“item_category”: “us”,
“currency”: “USD”,
“discount”: “0.00”,
“index”: 1,
“price”: 111,
“quantity”: 1
}
]
}
`
Tried to use a For loop in JavaScript Variable, but didn’t get the desired outcome. I’m keen to get the item names in a text format. What should I do?
Log in to reply.