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

  • Grayson

    Member
    25 June 2023 at 7:15 am

    You may be facing issues because your current variable setup doesn’t seem to be extracting the “item_name” data properly. You may need to adjust your JavaScript variable in Google Tag Manager so that it correctly accesses the “item_name” data from the dataLayer variable representing your “ecommerce.items”. After doing this, if you are still getting an array, you can use JavaScript’s join() method. This method can convert your array of “item_name” data into a single text string, with each item separated by a comma.

    Here’s a snippet of how you may adjust your code:

    `
    var itemslist = [];
    var products = {{dl – ecommerce.items}};
    for(i=0; i < products.length; i++){
    itemslist.push(products[i].item_name);
    }

    return itemslist.join(', ');
    `

    Doing so should give you the item names in a text format, separated by a comma.