Expand my Community achievements bar.

Capture all Array data in event


Level 1

For capturing data that is set in Array in JS data layer and match that with the product information of my orders I need to write a custom code. But I can't figure out what custom code I can use.

In analytics I want to make a breack-down per order to see which products are in the order and also can see the total price of the order and the price per product. 

In order.info.deposit you see the nett price per product, with that information  I want to measure the total nett price of the order. Now he is only capturing the first number/currency.




Hope someone can help me out.

1 Reply


Level 4

Hi Robbie!

Assuming the data layer is implemented properly, and the indices of the products match with indices of the order, you can try the below code which will pass all the values into products variable in Adobe Analytics. This is valid if you are using App Measurement, or Adobe Analytics Extension in your TMS. If you are using Web SDK to implement Adobe Analytics, the code will different.  

PS: This is only one of the ways it can be done, and there are many ways one can iterate through a data layer. I used forEach in one, and map/join in second. Maybe you can try using traditional for loop only. Also, you might need to add necessary checks like data layer is not equal to null or undefined, so please ensure that is also done. 



const productString = (data) => {
    let products = '';


            products = products +",;"+item+";"+data.product.productInfo.quantity[index]+";"+data.product.productInfo.price[index]+";;"
} else {

        products = ";"+item+";"+data.product.productInfo.quantity[index]+";"+data.product.productInfo.price[index]+";;";

return products;

s.products = productString(dataLayer);

//Optimized Code using map and join and $ if you are comfortable using some latest JS

const productString = (data) => {
    const productsArray = data.product.productInfo.name.map((item, index) => {
        return `;${item};${data.product.productInfo.quantity[index]};${data.product.productInfo.price[index]};`;

    return productsArray.join(",;");



The function iterates through all products and returns an appropriate product string for Adobe Analytics. Read more about products string if needed. 

The output is something like this below.