Wir haben lange Zeit nach einer Lösung Alternative zu Google Analytics gesucht gesucht. Die Contrib Piwik eCommerce Tracking für OsCommerce (OSC) V1.0 ist eine Lösung von Stefan Kanitz einem Staff Mitglied und Team Member der OsCommerce Germany Forums.
First open a editor an put this code in:
/*
$Id: logger.php,v 1.0 2011/12/09 19:25:43 jhtalk Exp jhtalk $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2011 osCommerce
Released under the GNU General Public License
All credits for this contrib goes to Stefan Kanitz (http://stefankanitz.de)
Support for this contrib: http://forums.oscommerce.de/index.php?showtopic=80084&st=0&p=380257&#entry380257
*/
function log_category($categories_id) {
global $languages_id;
$categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$categories_id . "' and language_id = '" . (int)$languages_id . "'");
$categories = tep_db_fetch_array($categories_query);
if (tep_not_null($categories['categories_name'])) {
$string = 'piwikTracker.setEcommerceView(productSku = false,productName = false,category = "'.$categories['categories_name'].'");' . "n";
}
return $string;
}
function log_product($products_id) {
global $languages_id;
$products_query = tep_db_query("select p.products_model, pd.products_name, cd.categories_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, ". TABLE_CATEGORIES_DESCRIPTION ." cd WHERE p.products_id = pd.products_id and p2c.categories_id = cd.categories_id and p.products_id = " . (int)$products_id . " and pd.language_id ='".(int)$languages_id."' and cd.language_id ='".(int)$languages_id."'");
$products = tep_db_fetch_array($products_query);
if (tep_not_null($products['products_model'])) {
$string = 'piwikTracker.setEcommerceView("'.$products['products_model'].'","'.$products['products_name'].'","'.$products['categories_name'].'");' . "n";
}
return $string;
}
function log_cart($products,$total) {
global $languages_id;
for ($i=0, $n=sizeof($products); $i<$n; $i++) { if (tep_not_null($products[$i]['model'])) { $categories_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION ." cd, ". TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE cd.categories_id = p2c.categories_id and p2c.products_id = " . (int)$products[$i]['id'] . " and cd.language_id ='".(int)$languages_id."'"); $categories = tep_db_fetch_array($categories_query); $string .= 'piwikTracker.addEcommerceItem("'.$products[$i]['model'].'","'.$products[$i]['name'].'","'.$categories['categories_name'].'",'.$products[$i]['final_price'].','.$products[$i]['quantity'].');' . "n"; } } $string .= 'piwikTracker.trackEcommerceCartUpdate('.$total.');' . "n"; return $string; } function log_order($insert_id,$order) { global $languages_id; for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { if (tep_not_null($order->products[$i]['model'])) {
$categories_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION ." cd, ". TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE cd.categories_id = p2c.categories_id and p2c.products_id = " . (int)$order->products[$i]['id'] . " and cd.language_id ='".(int)$languages_id."'");
$categories = tep_db_fetch_array($categories_query);
$string .= 'piwikTracker.addEcommerceItem("'.$order->products[$i]['model'].'","'.$order->products[$i]['name'].'","'.$categories['categories_name'].'",'.$order->products[$i]['final_price'].','.$order->products[$i]['qty'].');' . "n";
}
}
$string .= 'piwikTracker.trackEcommerceOrder("'.$insert_id.'",'.$order->info['total'].','.$order->info['subtotal'].','.$order->info['tax'].','.$order->info['shipping_cost'].',false);' . "n";
return $string;
}
function log_custom_v1($key,$value) {
$string = 'piwikTracker.setCustomVariable(1,"'.$key.'","'.$value.'","visit");' . "n";
return $string;
}
?>
Call this logger.php and upload it to the include folder.
Now follow the contrib instructions from point 2:
This contrib makes it possible to use the whole possibility of Piwik eCommerce Tracking for OSC.
1. Upload logger.php to /includes folder via FTP
2. In shopping_cart.php
After
require("includes/application_top.php");
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);
$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SHOPPING_CART));
insert this lines:
/* PIWIK E-Commerce Tracking */
$log_cart = log_cart($products,$cart->show_total());
tep_session_register('log_cart');
3. At the /includes/footer.php
Insert:
<!-- Piwik whith E-Commerce Tracking-->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.domain.de/piwik/" : "http://www.domain.de/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><font size="1"><a href="http://www.blog.ip-profis.de/piwik-ecommerce-tracking-for-oscommerce-osc/">Piwik E-Commerce Analytics for OSC</a></font><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
<?php
if ((basename($PHP_SELF) == FILENAME_DEFAULT) && tep_not_null($current_category_id)) {
if ($log_category = log_category((int)$current_category_id)) {
echo $log_category;
}
}
if (basename($PHP_SELF) == FILENAME_PRODUCT_INFO) {
if ($log_product = log_product((int)$HTTP_GET_VARS['products_id'])) {
echo $log_product;
}
}
if (basename($PHP_SELF) == FILENAME_SHOPPING_CART) {
if (tep_session_is_registered('log_cart')) {
echo $log_cart;
tep_session_unregister('log_cart');
}
}
if (basename($PHP_SELF) == FILENAME_CHECKOUT_SUCCESS) {
if (tep_session_is_registered('log_order')) {
echo $log_order;
tep_session_unregister('log_order');
}
}
?>
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
piwikTracker.setConversionAttributionFirstReferrer();
} catch( err ) {}
</script><noscript><p><img src="http://www.domain.de/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik E-Commerce Tracking Tracking Code -->
Do not forget to change this three lines to your Piwik settings:
a) var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.domain.de/piwik/" : "http://www.domain.de/piwik/");
b) var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
c) </script><noscript><p><img src="http://www.domain.de/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
You can get this settings at the Peiwik section where you can ad new Websites.
4.) /include/application_top.php
At the end of application_top.php right before
?>
Insert:
// Piwig logger.php fuer E-Commerce Tracking
require(DIR_WS_INCLUDES . 'logger.php');
5.) At checkout_process.php
After the section "lets start with the email confirmation":
After:
$email_order .= "" . EMAIL_TEXT_CONDITIONS_INFO;
tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
Insert:
// PIWIK E-Commerce Tracker
$log_order = log_order($insert_id,$order);
tep_session_register('log_order');
You can get support at the German OSC Forum under:
http://forums.oscommerce.de/index.php?showtopic=80084&st=0&p=380257entry380257
This great work was done by Stefan Kanitz (http://stefankanitz.de/) i (www.ip-profis.de) just write it down for you and translate it.
Die contrib habe ich auch bei OsCommerce hoch geladen: http://addons.oscommerce.com/info/8269
Support gibt es im OSC Deutschland Forum: http://forums.oscommerce.de/index.php?showtopic=80084&st=0&p=380257&#entry380257
So nun könnt ihre eure Campanen und Sales endlich tracken und das besser als mit Google Analytics.
Wer Piwik noch nicht hat kann es hier runter laden: Download
Hier die Demo von Piwik: Demo












































