Currently, I have setup tracking on my wordpress website using piwik. However, on top of that, I need to be able to track the e-commerce conversion and abandoned cart. I have managed to track the conversion manually but I have no idea on how do I replace the hardcoded values with the "woocommerce ordered products" values.
Here are what have I done so far:
- Installed WP-Piwik
- Installed WooCommerce Piwik integration
-
I created my custom javascript, called "piwik.js", and I hardcoded the values to track e-commerce purchases.
function addEcommerceItem() { // add the first product to the order _paq.push(['addEcommerceItem', "sku01", // (required) SKU: Product unique identifier "sku01Name", // (optional) Product name "productCategory", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"] 60, // (recommended) Product price 1 // (optional, default to 1) Product quantity ]); alert("e-Commerce item added!"); }; function trackEcommerceOrder() { _paq.push(['trackEcommerceOrder', "A10000127", // (required) Unique Order ID 35, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount) 30, // (optional) Order sub total (excludes shipping) 5.5, // (optional) Tax amount 4.5, // (optional) Shipping amount false // (optional) Discount offered (set to false for unspecified parameter) ]); alert("item tracked!"); };
-
On my Woocommerce, checkout page:
[woocommerce_checkout] <script type="text/javascript" src="http://myServerIP/mySite/piwik.js"></script> <script type="text/javascript"> addEcommerceItem(); trackEcommerceOrder(); </script>
And again, my question was how do I replace hardcoded values in
addEcommerceItem()
andtrackEcommerceOrder()
to reflect whatever products being purchased through my woocommerce site dynamically?
Thank you in advance