Monday, March 31, 2014

Ecommerce track code for virtuemart

This article explains you how to track your order status using google analytics.

Lets have a look .

Please find the below code:

<script type="text/javascript">

  var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'Your analytics code']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
   '<?php echo $trans['id']; ?>',           // transaction ID - required
   'Pantech', // affiliation or store name
   '<?php echo $trans['revenue']; ?>',          // total - required
   '<?php echo $trans['shipping']; ?>',           // tax
   '<?php echo $trans['tax']; ?>',          // shipping
   '',       // city
   '',     // state or province
   'India'             // country
]);
<?php
foreach($this->orderdetails['items'] as $item) { 
?>
_gaq.push(['_addItem',
   '<?php echo $trans['id']; ?>',           // transaction ID - necessary to associate item with transaction
   '<?php echo $item->order_item_sku; ?>',           // SKU/code - required
   '<?php echo $item->order_item_name; ?>',        // product name
   '<?php echo $item->virtuemart_category_name; ?>',   // category or variation
   '<?php echo $item->product_item_price; ?>',          // unit price - required
   '<?php echo $item->product_quantity; ?>'               // quantity - required
]);

<?php } ?>
_gaq.push(['_trackTrans']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
  
</script>

1 comment: