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:

<script>
(function () {

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

    })();
</script>

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.

Best,
Oliwer

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 product.id

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