Thank you so much for replying above Rod. I've had this installed on the site for around two weeks. I installed this because the Google Analytics code I used previously was only recording a few of the transactions when visiting the google Analytics site (Conversions>Transactions) but the majority were not being recorded. Unfortunately even though page views etc are being recorded correctly it seems the transactions are still not being recorded using this plugin. Has anyone else had the same issue? I spoke to somone from the Google 'Tag implementation team' over a week ago on the phone and after an hour he came up with this code to be inserted at the bottom of tpl_checkout_success_default.php , and when I did a test transaction and paid via my own paypal account the transaction was recorded, but none of the orders since have been recorded! I may be going around things the wrong way, but what I simply want is that all orders are recorded in Analytics, and in Adwords I can compare how much a campaign has cost for a certain period compared to the amount of revenue generated from those Ads during that period.
Would really appreciate any advice!
Code:
<?php
$sql_ordertotal = 'select REPLACE (text,"$","") text from orders_total where orders_id = '.$zv_orders_id.' and class = "ot_total"';
$to_send= $db->Execute($sql_ordertotal);
$order_total = $to_send->fields['text'];
$sql_ordershipping = 'select REPLACE (text,"$","") text from orders_total where orders_id = '.$zv_orders_id.' and class = "ot_shipping"';
$to_send = $db->Execute($sql_ordershipping);
$order_shipping = $to_send->fields['text'];
$sql_tax = 'select order_tax from orders where orders_id = '.$zv_orders_id;
$to_send = $db->Execute($sql_tax);
$order_tax = $to_send->fields['order_tax'];
?>
<script type="text/javascript">
ga('require', 'ecommerce');
var cartTotal = '<?php echo $order_total; ?>';
var CartShipping = '<?php echo $order_shipping; ?>';
var CartTax = '<?php echo $order_tax; ?>';
ga('ecommerce:addTransaction', {
'id': <?php echo $zv_orders_id ?>,// Transaction ID. Required.
'affiliation': 'welsh-lovespoons.co.uk', // Affiliation or store name.
'revenue': parseFloat(cartTotal.replace(/[^0-9.]/g,'')),// Grand Total.
'shipping': parseFloat(CartShipping.replace(/[^0-9.]/g,'')),// Shipping.
'tax':parseFloat(CartTax.replace(/[^0-9.]/g,''))// Tax.
});
<?php
$sql_orderproducts = 'select * from orders_products where orders_id = '.$zv_orders_id;
$row_orderproducts = $db->Execute($sql_orderproducts);
while(!$row_orderproducts->EOF){
$category_id = zen_get_products_category_id($row_orderproducts->fields['products_id']);
$category_name = zen_get_categories_parent_name($category_id);
?>
ga('ecommerce:addItem', {
'id': <?php echo $zv_orders_id ?>,// Transaction ID. Required.
'name': '<?php echo $row_orderproducts->fields['products_name']?>',// Product name. Required.
'sku': 'SKU<?php echo $row_orderproducts->fields['products_model']?>',// SKU/code.
'category': '<?php echo $category_name?>',// Category or variation.
'price': <?php echo number_format($row_orderproducts->fields['products_price'],2)?>,// Unit price.
'quantity': <?php echo $row_orderproducts->fields['products_quantity']?>// Quantity.
});
<?php
$row_orderproducts->MoveNext();
}
?>
ga('ecommerce:send');
</script>
Bookmarks