@alferz opened this Issue on June 4th 2017

The docs say to use the addEcommerceItem for every item in the cart prior to calling the trackEcommerceCartUpdate method. However only the trackEcommerceOrder method clears the internal eCommerceItems variable. This causes problems when an item is completely removed from the cart - even when using addEcommerceItem with qty 0, the item still gets sent to the server and the server tracks the deleted item as still being in the cart with qty 1.

A much cleaner mechanism would seem to be to just clear the internal eCommerceItems object after every CartUpdate in addition to track order. This of course necessitates using addEcommerceItem for every item in the cart on every change to it, but the docs already say to do that. Unless I'm missing a specific reason why CartUpdate doesnt clear eCommerceItems on purpose? I'm happy to submit a pull request for this one line change but wanted to see if there was a specific reason it was written this way.

@diosmosis commented on July 10th 2018 Member

I think the idea is that it's meant to match the behavior of a user, eg:

  1. user adds an item to the cart, code calls addEcommerceItem
  2. code calls trackEcommerceCartUpdate w/ the one item in the cart
  3. user adds an item to the cart, code calls addEcommerceItem
  4. code calls trackEcommerceCartUpdate, which has two items in the internal variable, just as there are two items in the user's cart

I think the problem is that there's no way to remove an item or clear the cart in the JS tracker if an item were to be removed from the user's cart or if the user's cart were cleared.

Maybe we should add two new methods, removeEcommerceItem and clearEcommerceCart. What do you think @matomo-org/core-team ? Would be a quick addition to 3.6.0.

@sgiehl commented on July 10th 2018 Member

for me it makes sense to add such methods

@tinect commented on July 10th 2018

Oh yes. please add such methods.

@tsteur commented on July 10th 2018 Member

Yes those methods be great. FYI: In PHP Tracker we also clear the items after calling trackEcommerceCartUpdate() but I presume we cannot do this as easily here re BC.

This Issue was closed on August 1st 2018
Powered by GitHub Issue Mirror