Ecommerce tracking API v2: cart add, remove and update

I had a couple questions about how to setup ecommerce tracking with the new API. I was following this topic at first How to set up ecommerce tracking?, but it seems the API used there is deprecated, and v2 API seems a bit confusing to me.

On my site’s cart page there is an input for the quantity of each product where you could easily add or remove a lot of each product. I was wondering how to implement the v2 API’s ecommerceAddToCart() and ecommerceRemoveFromCart() methods with this. Both need a quantity parameter to add/remove, meanwhile I only have a value for what it currently is; so it would be a lot easier for me to just call ecommerceCartUpdate(), however the Getting Started page for ecommerce tracking says it should only be called once per session and only for returning visitors. That is a problem for me!
So should I do something like: storing the value before the quantity in the input changes, then when it changes calculate the difference and if the new value is less it means products were removed so I call removefromcart, otherwise I call addtocart? There’s also the fact that since it is so easy to add/remove big quantities, I was wondering if it really makes sense to make so many calls? Is there a chance that one of these calls won’t go through and there will be a discrepancy between what is actually in the cart vs what Piwik last tracked?

EDIT: I forgot there was another question I had:) If I don’t track additions/removals at all on Piwik’s side, can I still call ecommerceOrder() if I can pass products in the cart from my site’s database? It seems like at least in the v1 version of the API you had to ‘register’ products with Piwik before updating the cart or confirming an order.

Hi Reggie.
our recommendation is to use ecommerceAddToCart() and ecommerceRemoveFromCart() functions, because events they produce are sent to the Analytics and that brings some useful stuff:

  • Data for metrics like: Adds to cart, Removes from cart, Cart-to-detail rate
  • Specific events so you can build a funnel with an Added to cart event as a step
  • Explore interactions with a cart on the user flow report

We recommend a setup where ecommerceCartUpdate() is used only once per session and before other cart-related functions but if that’s more convenient to you, go ahead and use only cart update. Though beware that you will lose the capabilities outlined in the above points because cart update is not sent to Analytics. It’s used only for the purpose of calculating abandoned carts after the session ends.

ecommerceOrder() is independent, you have to provide all the products from the cart within an Order event. It doesn’t matter how interactions with a cart were tracked, that data is used for cart-related metrics and abandoned carts but it’s not used for the order event.

Good luck in the implementation :crossed_fingers: