I want to capture only the "item_name" from my purchase dl for my other marketing tags. In this case, the dataLayer variable isn't helping. I can't use "ecommerce.items" since it gives the complete item information. Therefore I used a below JSV but I am getting the value in an array. How can I get it in text form separated by comma(,)?
JavaScript Variable in the 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;
Datalayer variable in GTM: ecommerce.items
Below is the 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
}
]
I tried using For loop in java script variable but it is not helping. I want item names in text format.
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.join(',');
Edited:
I see the problems now from this How can I get it in text form separated by comma(,)?
So you want to transfer something like
[a, b, c] to "a, b, c"
Above the code will work. You just need to join the array
Edited
Looks like I didn't see the push value is error from your code
var itemslist = [];
var products = {{dl - ecommerce - item name}};
for(i=0; i < products.length; i++){
itemlist.push(products[i].item_name)
// Here should only just push the name in it without key.
}
return itemlist.join(',');
Sorry about that and you can try again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.