Here is my code to add products in e-commerce order.
Any help would be appreciated why quantity is being tracked as zero? Thanks!
var items={{ order.line_items | json}};
var i;
for (i = 0; i < items; ++i) {
_paq.push(['addEcommerceItem',
items[i].sku, // (required) SKU: Product unique identifier
items[i].product_title, // (optional) Product name
"", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
items[i].price, // (Recommended) Product Price
1 // (Optional - Defaults to 1)
]);
Hi @Lukas ? Thank you so much for quick help. Sorry, it was my mistake in the code, I have updated it, but still showing quantity as zero instead of 1. There is also no logs for products.
var i;
for (i = 0; i < items.length; ++i) {
console.log(items[i].title);
console.log( items[i].price);
_paq.push(['addEcommerceItem',
items[i].sku, // (required) SKU: Product unique identifier
items[i].title, // (optional) Product name
"", // Category
items[i].price, // (Recommended) Product Price
1
]);
Let me also tell you that in my case the SKU is an empty string. Can you please guide me why products are not being tracked?
//Tracking Product Views in Matomo
var items={{ order.line_items | json}};
console.log(items);
for (var i = 0; i < items.length; ++i) {
_paq.push([‘setEcommerceView’,
“”, // (Required) productSKU
items[i].title, // (Optional) productName
“Accessories”, // (Optional) categoryName
items[i].price // (Optional) price
]);
}
//Tracking Category Views in Matomo
_paq.push([‘setEcommerceView’,
false, // Product name is not applicable for a category view.
false, // Product SKU is not applicable for a category view.
“”,
]);
//Adding a Product to the order
var i;
for (i = 0; i < items.length; ++i) {
_paq.push([‘addEcommerceItem’,
“123456789”, // (required) SKU: Product unique identifier
items[i].title, // (optional) Product name
[" Accessories"],
items[i].price, // (Recommended) Product Price
1 // (Optional - Defaults to 1)
]);
}
//Tracking the Ecommerce Order
_paq.push([‘trackEcommerceOrder’,
{{order.order_number}} , // (Required) orderId
{{order.total_price}}, // (Required) grandTotal (revenue)
{{order.total_price}}, // (Optional) subTotal
‘’, // (optional) tax
‘’, // (optional) shipping
false // (optional) discount
]);
The screenshot of Matomo also attached.