Issue with Ecom Tracking on GA3 Datalayer Event

Hi Piwik Community!

I have tried setting up an Order Confirmation Tag for Ecommerce Tracking that needs to be fired on one of our old GA3 Ecom Datalayer events.

This is how the Datalayer Event looks like(with example data in it):

	ecommerce: {
		currencyCode: "EUR",
		purchase: {
			products: [
					name: "Example Product Name",
					id: "12345",
					materialId: "AB12345",
					price: "11,50",
					quantity: 1,
					dimension11: "Test"
			actionField: {
				id: "1111112",
				revenue: 21.95,
				tax: 3.2,
				shipping: 10.45
	event: "eec.purchase"

This is how the Order Confirmation Tag looks like that fires on “eec.purchase”(below). I have tried to modify so it is according to Piwiks rules regarding the accepted data and data types for the different fields. The variable “subtotal” is a calculation we need to do also to get the correct data:

(function () {

  var products = {{ ecommerce }}.purchase.products;
  var grand_total = {{ ecommerce }}.purchase.actionField.revenue;
  var grand_shipping = {{ ecommerce }}.purchase.actionField.shipping;
    var subtotal = parseFloat(grand_total) - parseFloat(grand_shipping);
    var priceWithDot = parseFloat(product.price.replace(",", "."));
    _paq.push(["addEcommerceItem", product.sku,, product.category, priceWithDot, product.quantity]);
  _paq.push(["trackEcommerceOrder",{{ ecommerce }}, {{ ecommerce }}.purchase.actionField.revenue, {{ subtotal }}, {{ ecommerce }}, {{ ecommerce }}.purchase.actionField.shipping, {{ discount }}]);  


When I debug the tag while doing a purchase, the tag gets triggerd but no data is being sent to Piwik from what I can see in the Tracker Debugger. I get this error in the Console instead:

What is the issue here? And how can i modify the tag so it works?

Thanks in advance!

Hi @Dataguy,

Could you show where this directs to?

The “Cannot read properties of undefined (reading ‘length’)” error indicates that you are trying to access length of a variable that has undefined value, but I don’t see that in the script itself.


Hi @Oliwer_Kaczmarek ,

Thanks for the reply.

This is what “ppms.js:12” directs to:

The error comes from the fact that the SKU for products is empty. It is due to the fact that in the script itself you use product.sku where in dataLayer you have

Because SKU is undefined the length can’t be taken from it so that’s why the error message is: Cannot read properties of undefined (reading ‘length’)

1 Like