Catch cart events in Javascript layer


I need to catch events like:

Add to cart
Remove from cart
Visit product
Visit category
Change quantity of products in cart
And other checkout steps.

This events should be send via JavaScript library.
Is any pattern how I should do it?


Why do you want it to be done via JavaScript where there are such events in the PHP code?


My marketing automation provider require this way. I need to use special JS library which consist methos like library.addToCart(…) etc.


Have a look to - there are already implemented this features for Google Tag Manager.