Product purchase tracking with Tag Manager

Hi all,

To track an order with Matomo Tag Manager, there is this tutorial:

But how to track also the products associated with this order?

Tauschn asked the question in 2020 but didn’t get an answer: Measuring purchase order - products

Can anyone help me with this?

Thank you very much.

Hi Frédéric, ideally, the CMS pushes all purchase / cart / product data to the dataLayer.
In the TagManager variables section, you can retrieve those variables and use them in the corresponding tag.
It becomes a bit tricky, if one of the array nodes is an array (e.g. multiple products). Then, you’ll have to loop through this node and push the necessary infos to the addEcommerceItem method (within the tag).

For example (untested code):

<script type="text/javascript">
var productItems = {{Ecommerce - Product items}};

for (let i = 0; i < productItems.length; ++i) {
//Add product

if(productItems.length > 0) {
  _paq.push(['trackEcommerceCartUpdate', {{Ecommerce - Cart total}}]); 

Hi Peter,

Thanks a lot !

This is the situation I’m in (multiple products).

So please correct me if i’m wrong, I will have two tags on the confirmation page fired with the same ‘purchase’ event :

  • The one you wrote below (Cart update)
  • The one for purchase (Order)

And, in this situation the {{Ecommerce - Cart total}} variable used in the cart update could be used in the purchase tag as the total revenue ?

Again, many thanks for your help !

Hi Frederic,

the “addEcommerceItem” method call to add all the products is needed in two places - before calling the “cartUpdate” and before tracking the “ecommerceOrder”.
You can either double the “addEcommerceItem” code to be included in the cartUpdate and the ecommerceOrder tag, or you can build an “addEcommerceItem” tag that is called with a higher priority than “cartUpdate” or “ecommerceOrder” to add the products to the ecommerce tracking before the server requests are issued.

Cart update fires as soon as the customer puts the first or additional products into his/her cart, “ecommerceOrder” is called, as soon as the purchase is confirmed (“thank you page”).

The variables used in the example are structured in a different way, compared to the tutorial, so you have to build the variables the way you need them for your case. The total revenue can also be a nested array type like in the tutorial, that’s just personal taste.

Thank you Peter !

Have a nice afternoon.

1 Like