Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Extracting Ecommerce Purchase Item Names for GTM Marketing Tag › Reply To: Extracting Ecommerce Purchase Item Names for GTM Marketing Tag
-
Gotcha! You aimed to extract just the names of items from your dataLayer, and you were getting an array. But what you wanted was a text list separated by commas. The idea is to convert the array into a comma-separated string, right? If that’s the case, you were on the right track!
Your initial attempt put the entire ‘item_name’ object into your list. To correct this, you can revise your push command to grab only the item names i.e.,
products[i].item_name
, and collect those into youritemlist
array.The code should look like this:
`
var itemslist = [];
var products = {{dl – ecommerce – item name}};
for(i=0; i < products.length; i++){
itemslist.push(products[i].item_name); // just the item name
}
return itemslist.join(','); // join the array into a string
`
So, by correcting the push command and also using the
join
method, you’ll be able to convert the array into a string where its elements are separated by commas. I hope that helps! Give it another shot!