Post by GhostHunt » Thu Sep 05, 2013 2:05 am

I am trying to integrate google conversion tracking with OC 1.4.9.6. I have searched through the available information on the forums but I am having trouble piecing together the bread crumb trails for code segments that are useful for
OC 1.4.9.6 vs OC 1.5.X.X. It seems like various people came close or outlined a way but nothing seemed like a definitive "works for sure" kind of answers. So I thought maybe try to make a thread that definitively answers that question.

So far what I think I understand is this:

in /view/theme/*/template/common/success.tpl
we need to put this midified code after the footer

Code: Select all

<!---- Put after footer --->

<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>
<!-- tracking code goes here -->
<!-- Google Code for Purchase_Conversion Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXXXXXXXXXXXXXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "XXXXXXXXXXXXXXXXXXXXXXX";
var google_conversion_value = 0;
var google_remarketing_only = false;
/* ]]> */

if (1) {
  google_conversion_value = <?php echo round($ADtotal,2);?>;
}

</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/XXXXXXXXXXXX/?value=0&label=XXXXXXXXXXXXXXXX&guid=ON&script=0"/>
</div>
</noscript>

<?php } ?>
The part that seems vague to me is how to get the Order Total $ value or does Google need SKU, Model # and
$value per order line item?

Any guidance or assistance immensely appreciated.

New member

Posts

Joined
Thu Mar 18, 2010 8:58 am

Post by GhostHunt » Thu Sep 05, 2013 9:54 pm

Ok so after further analysis I have changed to this(below). Would an expert on OC be able to tell me if they have a reasonable feeling this would work on OC 1.4.9.6? Does anyone see anything wrong with this before I commit to
making these changes and testing?

Modifications to be made:

Mod 1:

in file /view/theme/*/template/common/success.tpl

Code: Select all

before 
<?php echo $footer; ?> 

<!-- begin ADD google tracking code -->

<?php if(isset($orderDetails) && isset($orderProducts)) { ?> 
<script type="text/javascript"> 
_gaq.push(['_addTrans', 
          '<?php echo $orderDetails['order_id']; /* orderId */ ?>', 
           <?php echo json_encode($orderDetails['store_name']); /* affiliation */ ?>, 
           '<?php echo $orderDetails['total']; /* total */ ?>', 
           '<?php if (isset($orderTax)) echo $orderTax[0]['value']; /* tax */ ?>', 
           '<?php if (isset($orderShipping)) echo $orderShipping[0]['value']; /* shipping */ ?>', 
           <?php echo json_encode($orderDetails['shipping_city']); /* city */ ?>,
           <?php echo json_encode($orderDetails['shipping_zone']); /* state */ ?>, 
           <?php echo json_encode($orderDetails['shipping_country']); /* country */ ?> ]); 
            
<?php foreach($orderProducts as $product) { ?> 
  _gaq.push(['_addItem', 
             '<?php echo $product['order_id']; /* orderId */ ?>', 
              <?php echo json_encode($product['model']); /* sku */ ?>, 
              <?php echo json_encode($product['name']); /* name (product) */ ?>,
             <?php echo json_encode('Products'); /* category */ ?>, 
             '<?php echo $product['price']; /* price */ ?>', 
             '<?php echo $product['quantity']; /* quantity */ ?>' ]); 
<?php } ?> 
_gaq.push(['_trackTrans']); 
           
</script>
<?php } ?>

<!-- end google tracking code -->    

Mod 2

In file /catalog/controller/checkout/success.php

Code: Select all

     if (isset($this->session->data['order_id'])) {
     
     <!-- begin ADD google tracking code -->
       
    
    $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']); 
    $this->data['orderShipping'] = $this->model_checkout_order->getOrderShipping($this->session->data['order_id']); 
    $this->data['orderTax']      = $this->model_checkout_order->getOrderTax($this->session->data['order_id']);
    
    
      <!-- end google  tracking code -->       
     
            $this->cart->clear();
Mod 3:

in file /catalog/model/checkout/order.php

Code: Select all

 
<!-- begin ADD google tracking code -->

public function getOrderProducts($order_id) { 
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'"); 
return $query->rows; } 

public function getOrderShipping($order_id) { 
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' AND 
code = 'shipping' AND EXISTS (SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' AND 
code = 'shipping') UNION SELECT 0, ". (int)$order_id. ", '', '', '', 0, 0 FROM " . DB_PREFIX . "order_total WHERE 
NOT EXISTS (SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' AND code = 'shipping')"); 
return $query->rows; } 

public function getOrderTax($order_id) { 
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE 
order_id = '" . (int)$order_id . "' AND code = 'tax' AND EXISTS (SELECT * FROM " . DB_PREFIX . "order_total WHERE 
order_id = '" . (int)$order_id . "' AND code = 'tax') UNION SELECT 0, ". (int)$order_id. ", '', '', '', 0, 0 FROM
 " . DB_PREFIX . "order_total WHERE NOT EXISTS (SELECT * FROM " . DB_PREFIX . "order_total WHERE 
 order_id = '" . (int)$order_id . "' AND code = 'tax')"); 
return $query->rows; } 

 <!-- end google  tracking code -->  
 
 <!-- BEFORE  -->
 
 public function create($data)



New member

Posts

Joined
Thu Mar 18, 2010 8:58 am

Post by GhostHunt » Mon Sep 09, 2013 10:01 pm

I am making good progress and the conversion tracking information has begun to arrive into google analytics.
I still have a few issues I need some help with. So any advice would be very welcome from the guru's out there.

During the success phases I would like to gather up the following but so far it has been elusive.

1) Shipping Total: not sure how to get this in OC 1.4.9. Would this work?

Code: Select all

 $this->data['orderDetails']['shipping_total'] = $this->session->data['shipping_method']['cost'];

2) Total Taxes : Would this work?

Code: Select all

 $tax = 0; foreach($this->data['order_products'] as $row){ $tax = $tax + $row['tax']; } $this->data['tax'] = $tax;
  '<?php echo $tax; ?>', // tax '
3) The following are showing up as empty strings?

Code: Select all

$orderDetails['shipping_city']
$orderDetails['shipping_zone'] 
$orderDetails['shipping_country']

New member

Posts

Joined
Thu Mar 18, 2010 8:58 am

Post by GhostHunt » Tue Sep 10, 2013 9:03 am

I have this working 100% now.

New member

Posts

Joined
Thu Mar 18, 2010 8:58 am
Who is online

Users browsing this forum: No registered users and 6 guests