//check to see if current page is checkout_success and include indextools for order if it is
if($page_directory == 'includes/modules/pages/checkout_success')
{
/**
* Based on
* jscript_google_analytics.php
*
* @package zen-cart statistic
* @copyright Copyright 2005-2006 Andrew Berezin
* @license
http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: jscript_google_analytics.php,v 1.0.0 18.08.2006 19:19 Andrew Berezin
[email protected] $
*/
$order_query = "select orders_id, " . GOOGLE_ANALYTICS_TARGET . "_city as city, " . GOOGLE_ANALYTICS_TARGET . "_state as state, " . GOOGLE_ANALYTICS_TARGET . "_country as country from " . TABLE_ORDERS . " where customers_id = :customersID order by date_purchased desc limit 1";
$order_query = $db->bindVars($order_query, ':customersID', $_SESSION['customer_id'], 'integer');
$order = $db->Execute($order_query);
$google_analytics = array();
$totals = $db->Execute("select value, class from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order->fields['orders_id'] . "' and (class = 'ot_total' or class = 'ot_tax' or class = 'ot_shipping')");
while (!$totals->EOF) {
$google_analytics[$totals->fields['class']] = number_format($totals->fields['value'], 2, '.', '');
$totals->MoveNext();
}
// UTM:T|[order-id]|[affiliation]|[total]|[tax]|[shipping]|[city]|[state]|[country]
$transaction = 'UTM:T|' . $order->fields['orders_id'] . '|' . GOOGLE_ANALYTICS_AFFILIATION . '|' . $google_analytics['ot_total'] . '|' . $google_analytics['ot_tax'] . '|' . $google_analytics['ot_shipping'] . '|' . $order->fields['city'] . '|' . $order->fields['state'] . '|' . $order->fields['country'];
$products = $db->Execute("select products_id, " . GOOGLE_ANALYTICS_SKUCODE . " as skucode, products_name, final_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $order->fields['orders_id'] . "'");
$items = "";
while (!$products->EOF) {
$category_query = "select cd.categories_name from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_CATEGORIES_DESCRIPTION . " cd on (cd.categories_id = p2c.categories_id) where p2c.products_id = '" . $products->fields['products_id'] . "' and cd.language_id = :languagesID limit 1";
$category_query = $db->bindVars($category_query, ':languagesID', $_SESSION['languages_id'], 'integer');
$category = $db->Execute($category_query);
// UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|[quantity]
$items .= ' UTM:I|' . $order->fields['orders_id'] . '|' . $products->fields['skucode'] . '|' . $products->fields['products_name'] . '|' . $category->fields['categories_name'] . '|' . number_format($products->fields['final_price'], 2, '.', '') . '|' . $products->fields['products_quantity'];
$products->MoveNext();
}