0

I need help with one particular topic. I want 2 custom javascript variables in Google Tag Manager. One should return the price of one or more products from one specific product VARIANT and the other variable should return the price of one or more products of the other product variant. I have found a custom javascript which does return the total price of all products in the ecommerce.purchase.products array, but I need 2 javascript codes which include an If statement. So to say "if the product has the product variant XY sum the price of all those products and return the price" Thanks a lot!

So I tried a lot but I am a rookie with javascript.

To get the total price of all products inside the products array works for me with that code:

function (){    
var prods = {{eCommerce purchase products}};  
var i;
var sum = 0;   
if (!prods) { return; }
for (i = 0; i < prods.length; i++) {    
sum +=parseFloat(prods[i].price*prods[i].quantity)  
}   
return sum; 
}

I just need an extension to say, "sum the price of all products of product_variant A"...

Krateros
  • 1
  • 1

0 Answers0