Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trackEcommerceCartUpdate Doesnt Clear Cart Items #11766

Closed
alferz opened this issue Jun 4, 2017 · 4 comments
Closed

trackEcommerceCartUpdate Doesnt Clear Cart Items #11766

alferz opened this issue Jun 4, 2017 · 4 comments
Assignees
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Milestone

Comments

@alferz
Copy link

alferz commented Jun 4, 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
Copy link
Member

diosmosis commented Jul 10, 2018

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
Copy link
Member

sgiehl commented Jul 10, 2018

for me it makes sense to add such methods

@tinect
Copy link

tinect commented Jul 10, 2018

Oh yes. please add such methods.

@tsteur
Copy link
Member

tsteur commented Jul 10, 2018

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.

@diosmosis diosmosis added this to the 3.6.0 milestone Jul 10, 2018
@diosmosis diosmosis self-assigned this Jul 29, 2018
@mattab mattab added the c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. label Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Projects
None yet
Development

No branches or pull requests

6 participants