Contributions
osCommerce Google Analytics module
This module allow you to integrade the advanced e-commerce Analysis provided by the new Google service named Analytics ( more info about the Google service on the official page: http://www.google.com/analytics/ ).
Support forum topic: http://forums.oscommerce.com/index.php?showtopic=180940
Expand All / Collapse All
osCommerce Google Analytics module V2.2 for E-commerce
Full package
Update by Nick Weisser and portafixe included!
Works with RC2a + MS2
Don't copy the patch "Added tax to single item price" below, due to some stripslashes, it miss all the slashes, so it will generate a parse error, and it will not works. Download the patch instead, and copy the code from there
The code was putting a coma instead of a dot for values over 1000$. Analytic was not tracking those sales. analytics.php file with fix :
if ($totals['class'] == 'ot_total') {
$analytics_total = number_format($totals['value'], 2, '.', '');
$total_flag = 'true';
} else if ($totals['class'] == 'ot_tax') {
$analytics_tax = number_format($totals['value'], 2, '.', '');
$tax_flag = 'true';
} else if ($totals['class'] == 'ot_shipping') {
$analytics_shipping = number_format($totals['value'], 2, '.', '');
$shipping_flag = 'true';
}
What does it does. More statistics than you could every want about your site and sales. You have to create an adword account (no need to spend money) with google and from there create your analitycs account. You won’t regret it..
Also you might want to add the vat plugin below if you use that.
Decapper
http://www.pricelessweddings.com.au
If your store uses VAT, you will have to change the $items_query and $item_string like so (based on tomashesseling's version from 15 Jan 2008):
$items_query = tep_db_query("select products_id, products_model, products_name, final_price, products_tax, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $order_id . "' order by products_name");
while ($items = tep_db_fetch_array($items_query)) {
$category_query = tep_db_query("select p2c.categories_id, cd.categories_name from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p2c.products_id = '" . $items['products_id'] . "' AND cd.categories_id = p2c.categories_id AND cd.language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
$item_string .= "pageTracker._addItem(n"" . $order_id . "","" . $items['products_id'] . "","" . $items['products_name'] . "","" . $category['categories_name'] . "","" . number_format(tep_add_tax($items['final_price'], $items['products_tax']), 2) . "","" . $items['products_quantity'] . "");n";
}
Google Analytics + E-commerce module.
in analalytics.php replace
// Prepare the Analytics "Transaction line" string
$transaction_string = '"' . $order_id . '","boxershortz","' . $analytics_total . '","' . $analytics_tax . '","0.00","' . $orders['customers_city'] . '","onbekend","' . $orders['customers_country'] . '"';
with:
// Prepare the Analytics "Transaction line" string
$transaction_string = '"' . $order_id . '"," ' . $analytics_affiliation . '","' . $analytics_total . '","' . $analytics_tax . '","' . $analytics_shipping . '","' . $orders['customers_city'] . '","' . $orders['customers_state'] . '","' . $orders['customers_country'] . '"';
Well,
We have altered the files, and tested it very good. The module is now working as it should be.
Also a small installation update in case your store is running on another domain than the actual website.
good luck.
Tomas Hesseling & Matieu Burgerhout
Dear all,
In the module as put down below by myself, there is a great error, shoppingcarts with multiple products are not registered as they should be in Analytics.
sorry for the inconvenience, we are debugging the script today and will post an update ASAP.
greetings Tomas Hesseling
(Re)written because of the new ga.js script.
future updates ar add-ons, see http://addons.oscommerce.com/info/5652
this is a complete package, based on osCommerce Google Analytics module v.1.2.2
I don't know if this makes a difference, but the piece of code that Google gave me had an additional element type="text/javascript" that isn't included in the prior module version. I updated it (see file) and am now seeing analytics stats whereas before I wasn't.
Remember to update the XX-XXXXXX-X with your Google Analytics ID.
Missing the closing </script> tag for the first script call in the post below... sorry about that :)
the download is just a text file with this fixed code:
<?php
$request_type = (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER);
if ($request_type == HTTPS_SERVER) {
define('GOOGLE_HTTP', 'https://ssl.');
} else {
define('GOOGLE_HTTP', 'http://www.');
}
?>
<script src="<?php echo((GOOGLE_HTTP) . 'google-analytics.com/urchin.js'); ?>">
</script>
<script type="text/javascript">
_uacct = "UA-1468672-1";
urchinTracker();
</script>
I encountered a server that reported HTTPS on port 80 thus loading the http url for google. Rather than delve into why Apache was reporting port 80, I decided to use stock OSC request_type to get it. This should be bullet proof and work for all installations.
<?php
$request_type = (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER);
if ($request_type == HTTPS_SERVER) {
define('GOOGLE_HTTP', 'https://ssl.');
} else {
define('GOOGLE_HTTP', 'http://www.');
}
?>
<script src="<?php echo((GOOGLE_HTTP) . 'google-analytics.com/urchin.js'); ?>">
<script type="text/javascript">
_uacct = "UA-XXXXXXX-X";
urchinTracker();
</script>
File is just the text file of this post with the exception that the text file has the url to get here :)
Enjoy! :)~
The code from the post below works great however some servers handle the environment varaibles differently with PHP. I needed the code below for a few servers that did not process the PHP code correctly. This will also handle SSL/NON-SSL so that the correct scripts are loaded from GOOGLE, avoiding the page security warnings.
Try this if your scripts are not loading/excuting with the code below. (check source code - if the script code is not being written with the code from the post below this one, try this).
I included both types of code snippets in the download file.
<?php
$request_type = (getenv('SERVER_PORT'));
if ($request_type == '443') {
define('GOOGLE_HTTP', 'https://ssl.');
} else {
define('GOOGLE_HTTP', 'http://www.');
}
?>
<script src="<?php echo((GOOGLE_HTTP) . 'google-analytics.com/urchin.js'); ?>">
<script type="text/javascript">
_uacct = "UA-xxxxxxx";
urchinTracker();
</script>
Hi there,
I was having a difficult time getting my shop to return the proper Google URL depending on connection type resulting in some browsers complaining about insecure items on secure pages.
In the end a quick mod to some code from here fixed it by changing request_type to SERVER_PORT
<?php if ( $_SERVER["SERVER_PORT"] == '443' ) { ?>
<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct="UA-xxxxx-x";
urchinTracker();
</script>
<?php
} else {
?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct="UA-xxxxx-x";
urchinTracker();
</script>
<? } ?>
Hope that helps someone.
Iggy
Hello- if you're using an sts template, the code needs to be added in the sts_template.html before </body> not in the footer php! My shop is tweeked so maybe that had something to do with it! Good luck-
PS the file is just a copy of this note
This version stops the google content from being displayed on a HTTPS connection which would cause many browsers to stop showing the padlock.
install instructions for use with sts4
you need the files fron the contrib below
This is for oscommerce users who do not want to use ecommerce tracking on there site.
This is a simple 1 step install
This Contribution works for germany and I guess for europe. E.g. in America you have to adjust the two code parts as the "," and the "." are used in another sequence...
When making an order with an amount above 1000 EUR it is recognized as 1 EUR in Google Analytics. Just replace your analytics.php file with the one offered as download here or do the following changes:
$analytics_total
change to
str_replace(",", "", $analytics_total)
and
number_format($items['final_price'], 2)
change to
str_replace(",", "", number_format($items['final_price'], 2))
This is the full osCommerce Google Analytics module v.1.2.2 with installation instructions for STS.
Just a small typo corrected.
1. Added the conditional code for the basic tracking code so the ssl and non-ssl pages are handled automatically now (file - checkout_success.php ).
Thanks to rrodkey and bfcase
2. Correctly moved the basic tracking code right above the </head> tag. Previously it was placed by mistake above the <head> tag (file - checkout_success.php ).
Thanks to zman818
3. Added the onLoad="java script:__utmSetTrans()" comand into the <body ... > tag (file - checkout_success.php ).
Thanks to mondo
Fixed a problem caused by a custom function.
Thank you Lyle.
This module allow you to integrade the advanced e-commerce Analysis provided by the new Google service named Analytics ( more info about the Google service on the official page: http://www.google.com/analytics/ ).
Support forum topic: http://forums.oscommerce.com/index.php?showtopic=180940
Note: Contributions are used at own risk.