Custom tracking for add to cart


I want to send the event on click of add to cart button using custom code but its not getting triggered.

Below is the code for the same.

_paq.push(["addEcommerceItem", "craft-311", "Unicorn Iron on Patch", "Crafts & Sewing", 499, 3]);

Any other way to implement it?


Below are the by default parameters that we can send when user clicked on add to cart button.

  • productSKU (string) – Required Product stock-keeping unit
  • productName (string) – Optional Product name
  • productCategory (string|Array) – Optional Product category or an array of up to 5 categories
  • productPrice (number) – Optional Product price
  • productQuantity (number) – Optional The number of units

Is there any way that we can send additional parameters along with the above default parameters? Please help its urgent

To be able to store the product, you have to either call the cart update or ecommerce order. It’s all documented here.

As for the second question, we’re not supporting the product-level custom dimension yet.

Thanks Kuba for replying.

It means that we can’t send the other event parameters on add to cart click except the default ones?

Also if i am trying to send the dynamic variable in place of constant values then event is not getting triggered.

Below is the sample code for the same.

_paq.push(["trackEcommerceCartUpdate", 6.00]);


Could you share the definition of those variables? Most likely the type of value isn’t correct. Have you checked if there are errors in browser’s console?

Hi Kuba,

Yes you are correct i am getting error in the browser’s console.
Error message is : Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘length’)

Does that mean we should have proper values in all the default parameters available in the ecommerce tracking method?


Yes. Could you paste the full code, including variable’s definition?

Hi Kuba,

Thanks for your help. It got resolved now.

As you told that Piwik don’t support the product-level custom dimension yet.
So if i go ahead and use the custom event tracking in place of by default ecommerce event tracking event then that custom event will populate in the ecommerce report.

In a nutshell: If we do the custom event tracking using the _paq.push([‘trackEvent’,eventCategory, eventAction,eventLabel,eventValue,nonInteractionNew]); for all the ecommerce tracking then do we get the report in the ecommerce report section of Piwik.

As i have to send a lot of extra event parameters along with the default parameters that’s why i am thinking of this approach.

Please suggest. Its really urgent.

Looking forward for your help in this regard.


It won’t work. If you really need more data, I’d suggest track it all with custom events without using ecommerce reporting.

Hi Kuba,

Thanks for the info.

I need one help here. Can we add the object in the piwik track event method.

Object will contain all the list of required custom dimension.

Below are the sample code.

_paq.push(['trackEvent',"remove_from_cart", dataDimension]);

Here dataDimension is the object which will contain all the list of custom dimension.

Custom event has 2 required params (category and action). Here’s a working example:

_paq.push(['trackEvent', eventCategory, eventAction, eventLabel, eventValue, { dimension1: "nonInteractionNew"}]);

The json object can contain multiple dimensions.

Ok. What if we want to send an object in the trackEvent rather than simply sending all the custom dimension one by one?

As I wrote, you can send multiple with one call.