#1 Go to your Google Analytics Settings -> Edit Settings -> Edit Main Website Profile -> E-Commerce Website : Yes
#2 Edit
includes/templates/your-template/common/html_header.php
At the very bottom just before </head>
Code:
<?php if ($request_type == 'NONSSL') { echo
'<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXX-1";
urchinTracker();
</script>'; }
else { echo
'<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXX-1";
urchinTracker();
</script>'; }
?>
</head>
#3 Create a new file:
includes/modules/pages/checkout_success/on_load_ga.js
Insert into the new file:
Code:
javascript:__utmSetTrans()
#4 Edit
includes/templates/template_default/tpl_checkout_success_default.php
At the very bottom add:
Code:
<?php
$ga_orders_id = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' order by date_purchased desc limit 1");
$ga_utm_t = $db->Execute("select order_total , order_tax, delivery_city, delivery_state, delivery_country from " . TABLE_ORDERS . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "'");
$ga_utm_t_delivery_country = $db->Execute("select countries_iso_code_2 from " . TABLE_COUNTRIES . " where countries_name = '" . $ga_utm_t->fields['delivery_country'] . "'");
$ga_utm_t_delivery_state = $db->Execute("select zone_code from " . TABLE_ZONES . " where zone_name = '" . $ga_utm_t->fields['delivery_state'] . "'");
$ga_utm_t_ship = $db->Execute("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "' && class = 'ot_shipping'");
$ga_utm_i = $db->Execute("select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "' order by products_name");
//$ga_utm_i_category = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $ga_utm_i->fields['products_id'] . "'");
//$ga_utm_i_category_name = $db->Execute("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $ga_utm_i_category->fields['categories_id'] . "'");
$ga_utm_i_array = array();
while (!$ga_utm_i->EOF) {
$ga_utm_i_array[] = array('product_id' => $ga_utm_i->fields['products_id'],
'name' => $ga_utm_i->fields['products_name'],
'price' => $ga_utm_i->fields['final_price'],
'quantity' => $ga_utm_i->fields['products_quantity'],
//'category' => $ga_utm_i_category_name->fields['categories_name']
);
$ga_utm_i->MoveNext();
}
?>
<form style="display:none;" name="utmform">
<textarea id="utmtrans">
UTM:T|<?php echo $ga_orders_id->fields['orders_id'] . '|' . "zencart" . '|' . $ga_utm_t->fields['order_total'] . '|' . $ga_utm_t->fields['order_tax'] . '|' . substr($ga_utm_t_ship->fields['value'], 0, 4) . '|' . $ga_utm_t->fields['delivery_city'] . '|' . $ga_utm_t_delivery_country->fields['countries_iso_code_2'] . '|' . $ga_utm_t_delivery_state->fields['zone_code']; ?>
<?php $ga_utm_i_array_displayed = array();
for ($i=0, $n=sizeof($ga_utm_i_array); $i<$n; $i++) {
if (!in_array($ga_utm_i_array[$i]['products_id'], $ga_utm_i_array_displayed)) {
echo ' UTM:I|' . $ga_orders_id->fields['orders_id'] . '|' . $ga_utm_i_array[$i]['product_id'] . '|' . $ga_utm_i_array[$i]['name'] . '||' . sprintf("%01.2f", $ga_utm_i_array[$i]['price']) . '|' . $ga_utm_i_array[$i]['quantity'];
}
}
?>