1) Move the following code from the catalog/controller/common/footer.php into the catalog/controller/common/header.php
Code: Select all
if ($this->config->get('google_analytics_status')) {
$this->data['google_analytics'] = html_entity_decode($this->config->get('google_analytics_code'), ENT_QUOTES, 'UTF-8');
}
else {
$this->data['google_analytics'] = '';
}
3) Remove $google_analytics from your footer.tpl file. It is right before the </body> tag at the bottom.
4) Add the following code to catalog/view/theme/default/template/common/success.tpl
Code: Select all
<?php if(isset($orderDetails) && isset($orderProducts)) { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_addTrans',
'<?php echo $orderDetails['order_id']; ?>',
'Store Name',
'<?php echo $orderDetails['total']; ?>',
'',
'',
'',
'',
''
]);
<?php foreach($orderProducts as $product) { ?>
_gaq.push(['_addItem',
"<?php echo $product['order_id']; ?>",
"<?php echo $product['product_id']; ?>",
<?php echo json_encode($product['name']); ?>,
"<?php echo $product['model']; ?>",
"<?php echo $product['price']+($product['price']*$product['tax']/100); ?>",
"<?php echo $product['quantity']; ?>"
]);
<? } ?>
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
(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>
<?php } ?>
5) Add these lines to catalog/controller/checkout/success.php:
Code: Select all
$this->load->model('checkout/order');
$this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$this->data['orderProducts'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);
Code: Select all
$this->cart->clear();
Code: Select all
public function getOrderProducts($order_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
return $query->rows;
}
Hope it works for you. I was noticing some of my transactions were missing before I did the json_encode on the product name. Oops