I've done a refactoring of this module and implemented the ecommerce cart update and product view tracking that is missing. The refactor requires this patch for the Piwik module: https://www.drupal.org/node/2196621#comment-8484791

It's annoying that I had to use a patch for Piwik module, but the patch makes implementation of the commerce tracking MUCH MUCH cleaner. Unfortunately, the Piwik module maintainer has postponed the patch implementation awaiting the results of a 6-year-old issue in Google Analytics module. So, I'm not holding my breath that the patch will be accepted.

Regardless, the patch to Piwik is really small and simple. It adds a hook that allows you to add javascript code before the call to trackPageView. I can then implement that hook in Commerce Piwik to insert the commerce tracking in the correct order. It simplifies the javascript injection a bunch, and the hook_init() that was used before is no longer necessary. It also fixes an issue commented on it the code, where order complete tracking can require a page load after the order complete page in order to be registered.

Summary of the changes in this patch:

  • Refactored existing code to use hook_piwik_add_push(), from the patch linked above.
  • Added cart add/remove/update tracking, using commerce_cart hooks and the update cart form with a form_alter. This allows you to track abandoned carts in Piwik.
  • Added product view tracking with a form alter on the add to cart form. If the user views the add to cart form for a product, it will register as a product view. I've tested this, and it works great, even when you have multiple products assigned to a single display. It can catch the different products as you select them.

This patch doesn't do anything for categories. They are still unimplemented.

One note for testing this: Piwik apparently treats all carts as abandoned immediately when you create them. Then, if the order is completed, they are converted from abandoned to an order. So, with this version, you will see an abandoned cart in the ecommerce log as soon as you add something to your cart. But, it appears to update that abandoned cart correctly as you add/remove products, and it converts it correctly to an order on checkout.

I realize that there are a lot of changes in this patch, so the maintainer may not want to deal with it. But, it's working well over here so I thought I'd post it for whoever may find it.

Comments

zengenuity’s picture

Status: Active » Needs review
StatusFileSize
new6.92 KB