Patrick
At Tealium we do not like to utilize the javaScript Extension unless it is necessary. In your case we do not have an extension that will sum values in an array, so we need javaScript to help us out.
Here is what the code below is doing:
When any event occurs
Check to make sure the user is on the receipt page
Then check to make sure product_quantity is an array
If those checks are true then create a order_item_count and set it to zero.
Then loop through all the product quantities and add them to the count
Finally return the value in string format to follow our best practices.
if(b['page_type'] === 'receipt' && utag.ut.typeOf(b['product_quantity']) === 'array'){
b['order_item_count'] = 0;
for(var i in b['product_quantity']){
b['order_item_count'] += parseInt(b['product_quantity'][i]);
}
b['order_item_count'] = b['order_item_count'] + "";
}
I will also add another comment with a screenshot of the extension.
The code assumes your order confirmation page has the page_type of receipt, your product array has the name product_quantity and the final data source you are wanting to populate is order_item_count. Also this code assumes you are using utag version 4.35 or greater so that utag.ut.typeof will be available.
If any of this is confusing, please feel free to reach out to your Account Manager to get an engineer to look at your specific use case.
Happy Tracking!
Bk