Manual install of ecommerce tracking (especially cart updates)



In the past several weeks i have struggled to implement the ecommerce tracking myself because there is no plugin to do that for the platform i am using (jigoshop) and they have no intention to change that in the future.

So, being no php-programmer it was pretty hard but i did manage to make orders tracking work by installing code found on the piwik help section, in the “thank you” page. OK, i do not know how to make the javascript code “loop” through products (// Here you can add other products in the order[…]) but i am happy with just the total value of the order. But this was easy because it was on the “thank you” page.

Cart updates on the other hand is much harder to achieve… even the simplest thing, to get just the updated total value of the cart, not products, names and stuffs… If i put the code via onclick of the “add to cart” button telling it to fetch the total cart amount, the code is run upon page loading and BEFORE the actual adding to cart, so it sends to piwik outdated data… The subsequent actions do make the cart value increase with previous additions to the cart, but i am always one step behind because it is excluding the current, last action done.

Ok, i figure to add the code in the footer of theproduct page template, because i have noticed that the product page is actually refreshing itself after the product is added, so that would mean freshness of data. I put a condition to run the code only if cart total >0 and started testing. And although the javascript ALWAYS outputs the correct value of the cart totals, piwik seems to randomly update/ignore that. Most likely because I believe there are 2 javascripts outputs sent one after another in 1-2 seconds, one old and one new. Eg if I am taking 10 actions on the same page adding products in each of them, piwik live widget cart value sometimes will be one-two-three-etc clicks behind, others times will just all of a sudden catch up and get the correct number. And this is frustrating, because sometimes it is working as it should, sometimes it is better to not work at all and just drop it :smiley:

Any ideas? Best way would be to make the onclick javascript of the “add to cart” button (which always, absolutely always working correctly and never skips an update ) run after the actual products are added… and not when the product page is loaded… but i dont know how to do that, or if possible.

thanks for any input on this