Below are some notes on how I implemented Google eCommerce Tracking with my osCommerce store. You can view Google’s instructions on enabling e-commerce tracking here:
In order to add Google transactions tracking to my osCommerce store I needed to edit both the checkout_success.php and footer.php files. I edited both these files because I’m already using Google Analytics to track users and there is a dependency in the files which must come before the e-commerce tracking portion.
Therefor, I edit checkout_success.php in order to capture the correct information and keep the Google Analytics javascript code in the footer so that it continues to be global.
First edit checkout_success.php
Your first order of business is increasing the information (elements) in the ‘orders’ array.
Find the following line:
$orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$customer_id . "' order by date_purchased desc limit 1");
Change to:
$orders_query = tep_db_query("select orders_id, customers_city, customers_state, customers_country from " . TABLE_ORDERS . " where customers_id = '" . (int)$customer_id . "' order by date_purchased desc limit 1");
You’ll now want to increase the information (elements) in the products_array.
Find the Following lines:
$products_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = ‘" . (int)$orders['orders_id'] . "
‘ order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
$products_array[] = array(
'id' => $products['products_id'],
'text' => $products['products_name']);
}
Change to:
$products_query = tep_db_query("select products_id, products_name, products_model, products_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
$products_array[] = array (
'id' => $products['products_id'],
'sku' => $products['products_model'],
'cost' => number_format($products['products_price'], 2, '.', ''),
'num' => $products['products_quantity'],
'text' => $products['products_name']);
}
You’ll then want to add a new array called addTrans. Add the following code block before the end of the closing php tag directly below the code above. This will be around line 66:
/* ADDED TO GET ORDER TOTAL FOR GOOGLE ADWORDS CONVERSION TRACKING CODE VALUE */
/* by Ed Reckers */
/* October, 2008 */
// get transaction data for ._addTrans
$addTrans = array();
$addTrans['orders_id'] = (int)$orders['orders_id'];
$orderstotal_query = tep_db_query("select class, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "'");
while ($order_total = tep_db_fetch_array($orderstotal_query)) {
$addTrans[$order_total['class']] = number_format($order_total['value'], 2, '.', ");
}
/* End GOOGLE ADWORDS (see below for Google's Script) */
Now edit footer.php
At the foot of the document, above the final closing php tag and below the html comment (end pageContainer); add the following:
In a nutshell, that’s pretty much how I was able to implement Google eCommerce Tracking with my osCommerce store
Below are some links I found helpful in this work:
- Google Help Page eCommerce Tracking
- Google Tracking API eCommcerce
- Google Groups eCommcer Tracking Multiple Items
If you have any questions regarding the implementation of Google eCommerce Trracking with your osCommerce store feel free to email me any specifics along with some contact information from my contact form at my business Web site Kliky.Com.