Actually, you can track all of the following by inserting code (into two different files) into the tpl_footer.php file AND /includes/modules/pages/checkout_success/header_php.php
(again, this works perfectly, but it may be much easier / faster to use the mod). I listed the code below to do it all (if you must insert by hand). I have been using it on a few Zen installs for over 6 months now with no problems.
To do all of the above and PLUS add "Google Conversion Tracking" as well to the mix, the following code should be inserted at the bottom of the tpl_footer.php (or tpl_main_page just above the closing </BODY> tag)
Keep in mind that the "xxxxxxx" shown in all areas below represents where your own Google ID would go (generated from within Google).
Also keep in mind that if you would like to actually track the "conversion value" (to get more accurate cost data for PPC reporting) then you would replace
if (1.0) {
google_conversion_value = 1.0;
}
with
if (echo $zv_order_total_cd) {
google_conversion_value = echo $zv_order_total_cd;
}
Ok, on with the code again, inserted at the bottom of the tpl_footer.php (or tpl_main_page just above the closing </BODY> tag)
PHP Code:
<!-- Tracking -->
<?php // If page is SSL then use Secure Code
if($_SERVER['HTTPS']=='on'){
?>
<!-- Google Analytics -->
<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
<!-- /Google Analytics -->
<?php
if ($_GET['main_page']=="checkout_success") { // if transaction is a successful purchase then record the order details
?>
<!-- Google Analytics E-Commerce Tracking (must go below standard Analytics code)-->
<body onLoad="javascript:__utmSetTrans()">
<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|<?php echo $zv_orders_id ?>||<?php echo $zv_order_total_cd ?>|<?php echo $zv_order_tax ?>|0.00|<?php echo $zv_order_city ?>|<?php echo $zv_order_state ?>|<?php echo $zv_order_country ?>
<?php // Loop through products purchased to track in Google (these come from the "cart_orders_products TABLE)
//sku = "products_model"; productname = "products_name"; category = ""; price = "final_price"; quantity = "products_quantity"
$products_displayed_google = array();
for ($i=0, $n=sizeof($products_array_google); $i<$n; $i++) {
if (!in_array($products_array_google[$i]['id'], $products_displayed_google)) {
echo 'UTM:I|' . $zv_orders_id . '|' . $products_array_google[$i]['model'] . '|' . $products_array_google[$i]['text'] . '||' . $products_array_google[$i]['price'] . '|' . $products_array_google[$i]['quantity'];
$products_displayed_google[] = $products_array_google[$i]['id'];
}
}
?>
</textarea>
</form>
<!-- /Google Analytics E-Commerce Tracking -->
<!-- Google Code for purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "FFFFFF";
if (1.0) {
var google_conversion_value = 1.0;
}
var google_conversion_label = "purchase";
//-->
</script>
<script language="JavaScript" src="https://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src="https://www.googleadservices.com/pagead/conversion/xxxxxxxxxx/?value=<?php echo $zv_order_total_cd ?>&label=purchase&script=0">
</noscript>
<?php } //End if main page is "checkout_success"?>
<?php // Else use Non-Secure Code
} else {
?>
<!-- Google Analytics -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
<!-- /Google Analytics -->
<?php } ?>
<!-- / Tracking -->
The above code does the following:
1) Checks whether or not the page is a Secure page and then uses the appropriate code based on that check (secure or not secure)
2) Inserts Google Analytics Tracking
3) Inserts Google E-Commerce Tracking
4) Inserts Google Conversion Tracking.
Then, insert the following code into the /includes/modules/pages/checkout_success/header_php.php file just below the following line
$zv_order_total_cd = $orders->fields['order_total']; (approximately line # 74.
PHP Code:
// Added the below field for Google Analytics E-commerce Tracking (in the footer file)
$zv_order_tax = $orders->fields['order_tax'];
$zv_order_city = $orders->fields['delivery_city'];
$zv_order_state = $orders->fields['delivery_state'];
$zv_order_country = $orders->fields['delivery_country'];
// Google Analytics Tracking (This can be removed and not harm anything)
//Altered code below to accomdate additional fields that Google Analytics can Track
$products_query = "select products_id, products_name, products_model,products_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . $zv_orders_id . "'
order by products_name";
$products_google = $db->Execute($products_query);
//********************Google codes**************************
while (!$products_google->EOF) {
$products_array_google[] = array('id' => $products_google->fields['products_id'],
'text' => $products_google->fields['products_name'],
'model' => $products_google->fields['products_model'],
'price' => $products_google->fields['products_price'],
'quantity' => $products_google->fields['products_quantity']);
$products_google->MoveNext();
}
//*************************End Google Codes*******************
// End Google Analytics Code
Everything Google offers for the most part and then some. It can be done, just requires more steps to complete.
Bookmarks