Ecommerce Tracking with Piwik 2.0

Hello,

I’ve been checking out info for ecommerce tracking, and between seeing old info and conflicting info, I could use some clarity/confirmation.

From my reading, we can track:
[ul]
[li] Product & Category Views
[/li][li] Cart Add/Update
[/li][li] Order Complete
[/li][/ul]

Let’s assume that this is the structure of the website:
[ul]
[li] Category.php
[/li][li] Product.php
[/li][li] Cart.php
[/li][li] Confirmation.php
[/li][/ul]

Are the following examples correct? Notice which function is used where, and where trackPageView is added :::::

[size=large]Category.php[/size]


<!-- Piwik --> 
<script type="text/javascript"> 
var _paq = _paq || []; 
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/"); 
_paq.push(['setSiteId', {$IDSITE}]); 
_paq.push(['setTrackerUrl', u+'piwik.php']); 


_paq.push(['setEcommerceView',false,false,"{$CATEGORYNAME}"]);


_paq.push(['trackPageView']); 
_paq.push(['enableLinkTracking']); 
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s); })();
 </script> 
<!-- End Piwik Code -->

[size=large]Product.php[/size]


<!-- Piwik --> 
<script type="text/javascript"> 
var _paq = _paq || []; 
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/"); 
_paq.push(['setSiteId', {$IDSITE}]); 
_paq.push(['setTrackerUrl', u+'piwik.php']); 


_paq.push(['setEcommerceView',"{$PRODUCTID}","{$PRODUCTNAME}","{$CATEGORYNAME}",{$PRODUCTPRICE}]);


_paq.push(['trackPageView']); 
_paq.push(['enableLinkTracking']); 
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s); })();
 </script> 
<!-- End Piwik Code -->

[size=large]Cart.php[/size] – (When clicked “ADD TO CART” on Product.php – Fire each time Item Added)


<!-- Piwik --> 
<script type="text/javascript"> 
var _paq = _paq || []; 
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/"); 
_paq.push(['setSiteId', {$IDSITE}]); 
_paq.push(['setTrackerUrl', u+'piwik.php']); 


_paq.push(['addEcommerceItem',"{$PRODUCTID}","{$PRODUCTNAME}","{$CATEGORYNAME}",{$PRODUCTPRICE},{$QUANTITY}]);
_paq.push(['trackEcommerceCartUpdate',{$CARTSUBTOTAL}]);


_paq.push(['trackPageView']); 
_paq.push(['enableLinkTracking']); 
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s); })();
 </script> 
<!-- End Piwik Code -->

[size=large]Cart.php[/size] – (Handling Changes)

Questions:
[ul]
[li] When item is removed, do you just change the Quantity to 0 and update Subtotal?
[/li][li] When/if system changes the price of the item (promotion code?) do you just refire the same (pid) with the price different?
[/li][/ul]


<!-- Piwik --> 
<script type="text/javascript"> 
var _paq = _paq || []; 
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/"); 
_paq.push(['setSiteId', {$IDSITE}]); 
_paq.push(['setTrackerUrl', u+'piwik.php']); 

# IF ITEM REMOVED:  QUANTITY=0, SUBTOTAL = NEWSUBTOTAL
# IF ITEM PRICE CHANGED:  PRODUCTPRICE = NEWPRODUCTPRICE, SUBTOTAL = NEWSUBTOTAL

_paq.push(['addEcommerceItem',"{$PRODUCTID}","{$PRODUCTNAME}","{$CATEGORYNAME}",{$PRODUCTPRICE},{$QUANTITY}]);
_paq.push(['trackEcommerceCartUpdate',{$CARTSUBTOTAL}]);


_paq.push(['trackPageView']); 
_paq.push(['enableLinkTracking']); 
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s); })();
 </script> 
<!-- End Piwik Code -->

[size=large]Confirmation.php[/size] – (After Payment on Cart.php)

Questions:
[ul]
[li] The discount value, is that an Amount value (10.00) or just true/false (false if unset)?
[/li][li] On the documentation, it says: “// we recommend to leave the call to trackPageView() on the Order confirmation page” can you clarify this? What do you mean? Where/When/Why do we NOT use trackPageView() and then use on Confirmation page.
[/li][/ul]


<!-- Piwik --> 
<script type="text/javascript"> 
var _paq = _paq || []; 
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/"); 
_paq.push(['setSiteId', {$IDSITE}]); 
_paq.push(['setTrackerUrl', u+'piwik.php']); 


_paq.push(['trackEcommerceOrder',"{$ORDERID}",{$TOTAL},{$SUBTOTAL},{$TAX},{$SHIPPING},{$DISCOUNT}]);


_paq.push(['trackPageView']); 
_paq.push(['enableLinkTracking']); 
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s); })();
 </script> 
<!-- End Piwik Code -->

[size=large]LASTLY…[/size] If using ecommerce tracking, how would you track:
[ul]
[li] Applying/Removing Promotion Codes on Cart.php
[/li][li] Price Changes on Cart.php
[/li][li] Value Add Items (not added by user action, but removable with promotion code)
[/li][/ul]

Thank you in advance for your help! :slight_smile:

This looks correct from a quick scan. It should work for you…

Thanks for the reply Matt. Would you please address the questions under the red [size=large]Questions[/size] as those have me stuck in waiting.

Thank you