How to get variables from GTM datalayer into Piwik?


I’m trying to set up tracking for add to cart - I have a datalayer that was set up for GTM, and I can see it fine with _stg_debug, but I can’t get Piwiks Tag Manager to fetch data for variables or even show addToCart as an event in the tracker debugger even though the tag is fired.

I see the event and datalayer fine in _stg_debug:

I’m using this tag:

(function () {

  window._paq = window._paq || [];
  var products = {{addProducts}};
    _paq.push(["addEcommerceItem",,, product.category, product.price, product.quantity]);


And this datalayer variable:

What am I doing wrong? :confused:

Hi. You have to update cart or send an order after adding products to the cart. It’s documented here.

This function does not send any data to Collecting & Processing Pipeline. It only prepares the virtual shopping cart to be sent with trackEcommerceCartUpdate or trackEcommerceOrder.

Also, keep in mind that we don’t support yet nested datalayer variables (but that should change soon). :slight_smile:


Okay, well then it makes sense the cart update isn’t doing what I want, if it’s only to get the cart total, since I don’t have that value in my datalayer :slight_smile:

I was just testing on that event since it was easier to test than making orders, but I copypasted the solution from Unable to fetch enhanced ecommerce dataLayer values - #4 by pslonina to get conversions to work, so now I’m just hoping it will show up in the ecommerce overview at some point

  • or do I need to figure out how to get the cart update to work for ecommerce data to show there?

If the events appear in the tracker debugger, it’s all fine.

Perfect, thank you :slight_smile:

I can see it now, so that’s great!

Data on all standard reports appears with ~30 mins delay. :slight_smile:

1 Like