Ecommerce variables


#1

I am having having a little trouble understanding how Matomo, when the E-commerce setting is active in the account, knows which variable in the code below relates to which E-commerce value. E.g. What prevents the Category name being shown as the Product name and the Quantity being shown as the price? As it looks like you could name the Custom Data Layer Variables anything you’d like. This differing to the Google approach where all fields must be named and structured in a particular way as GA will read the data straight from the data layer.

In an attempt to try and be more descriptive, my understanding breaks between the following points:

  1. Adding the Custom Data Layer Variables into the code in the Matomo tags. Here the custom variables have been created based on the data layer pushes that have been implemented on the site and added to the html code in the tag:

[…]
// add the first product to the order
_paq.push([‘addEcommerceItem’,
“{{Data Layer - Product SKU}}”,
“{{Data Layer - Product Name}}”,
“{{Data Layer - Product Category}}”,
“{{Data Layer - Product Price}}”,
“{{Data Layer - Product quantity}}”,
]);

_paq.push([‘trackEcommerceOrder’,
“{{Data Layer - Unique Order ID}}”,
“{{Data Layer - Order Revenue}}”,
“{{Data Layer - Order sub total}}”,
“{{Data Layer - Tax amount}}”,
“{{Data Layer - Shipping amount}}”,
“{{Data Layer - Discount offered}}”
]);

  1. Matomo knowing which custom Data Layer variable relates to which Ecomm field, as presumably you can name the Custom Variables whatever you want e.g. it could be ‘Product SKU’ or ‘SKU’ or ‘Unique SKU’ or ‘Data Layer - SKU’.

How does the Matomo system know to pull the SKU information as the unique product identifier?

Is it based on their order in the code e.g. for the ‘addEcommerceItem’ example above: 1st position is SKU, 2nd position is Product Name, 3rd position is Product Category?

And then if that is true, what happens if you don’t want to track/don’t have a ‘Data Layer - Product Name’ to track BUT you do have a ‘Data Layer - Product Category’? Would you leave the Product variable in so as to not upset the order or is that not necessary. I know this example is unlikely to happen but hopefully it will help clearing this up as the field is apparently not a must have, so what would the code look like if we didn’t have it.

I hope this is somewhat clear and thanks in advance!