HowTo:Google Analytics einbinden

Aus WEB-Shop Software Wiki
Version vom 9. April 2009, 17:17 Uhr von Xantiva (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „= HowTo: Google Analytics einbinden (via Template) = Google bietet mit [http://www.google.com/analytics/de-DE/ Analytics] einen kostenlosen Dienst für Besucher,...“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springenZur Suche springen

HowTo: Google Analytics einbinden (via Template)

Google bietet mit Analytics einen kostenlosen Dienst für Besucher, ecommerce, etc. - Statistiken. Grundsätzlich ist Analytics bei Datenschützern nicht unumstritten, aber bietet im Gegensatz zu dem bereits in der ECB Shop Software eingebauten Piwik (OpenSource) das ecommerce Tracking an.

Der nachfolgende Code muss im Template in die bottom.js.php eingebaut werden. Wenn die Datei noch nicht vorhanden ist, einfach eine neue erstellen. Es ist also KEINE Änderung am eigentlichen Shop mehr erforderlich!

<?php
/* 
 * Implementation of the Google Analytics code, including the
 * ecommerce tracking.
 *
 * Mike Kuester, http://www.xantiva.de/
 *
 * Snippets from http://webanalyse-news.de/xtcommerce-tracking-mit-google-analytics-tutorial/
 *
 */
?>
<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
    try {
        var pageTracker = _gat._getTracker("UA-xxxxxx-1");
        pageTracker._trackPageview();
<?php
/*
 * The following code provides the ecommerce data for Google Analytics
 * on the checkout_success.php page:
 */
if  (strpos($_SERVER['PHP_SELF'], '/checkout_success.php') !== false) {
    $orders_total_shipping_query = xtc_db_query("SELECT value FROM ".TABLE_ORDERS_TOTAL." WHERE orders_id = '".$last_order."' AND class='ot_shipping'");
    $orders_total_shipping = xtc_db_fetch_array($orders_total_shipping_query);
    $orders_total_tax_query = xtc_db_query("SELECT value FROM ".TABLE_ORDERS_TOTAL." WHERE orders_id = '".$last_order."' AND class='ot_tax'");
    $orders_total_tax = xtc_db_fetch_array($orders_total_tax_query);
    $orders_total_query = xtc_db_query("SELECT value FROM ".TABLE_ORDERS_TOTAL." WHERE orders_id = '".$last_order."' AND class='ot_total'");
    $orders_total = xtc_db_fetch_array($orders_total_query);
    $orders_query = xtc_db_query("SELECT customers_city, customers_state, customers_country FROM ".TABLE_ORDERS." WHERE orders_id = '".$last_order."'");
    $orders = xtc_db_fetch_array($orders_query);
    echo 'pageTracker._addTrans("'.$last_order.'", "'.STORE_NAME.'", "'.$orders_total['value'].'", "'.$orders_total_tax['value'].'", "'.$orders_total_shipping['value'].'", "'.$orders['customers_city'].'", "'.$orders['customers_state'].'", "'.$orders['customers_country'].'" );' . "\n";
    $order_query = xtc_db_query("SELECT categories_name,
                                        p.products_id,
                                        orders_products_id,
                                        products_model,
                                        products_name,
                                        products_price,
                                        products_quantity
                                 FROM   ".TABLE_ORDERS_PRODUCTS." p,
                                        ".TABLE_PRODUCTS_TO_CATEGORIES." ptc,
                                        ".TABLE_CATEGORIES_DESCRIPTION." cd
                                 WHERE  p.products_id = ptc.products_id
                                   AND  ptc.categories_id=cd.categories_id
                                   AND  cd.language_id = '".$_SESSION['languages_id']."'
                                   AND  orders_id='".$last_order."'
                                 GROUP BY p.products_id");
    $order_data = array ();
    while ($order_data_values = xtc_db_fetch_array($order_query)) {
        $order_data = array ('PRODUCTS_MODEL' => $order_data_values['products_id'],
                             'PRODUCTS_NAME' => $order_data_values['products_name'],
                             'CAT' => $order_data_values['categories_name'],
                             'PRODUCTS_SINGLE_PRICE' => $order_data_values['products_price'],
                             'PRODUCTS_QTY' => $order_data_values['products_quantity']);
        echo 'pageTracker._addItem("'.$last_order.'", "'.$order_data['PRODUCTS_MODEL'].'", "'.$order_data['PRODUCTS_NAME'].'", "'.$order_data['CAT'].'", "'.$order_data['PRODUCTS_SINGLE_PRICE'].'", "'.$order_data['PRODUCTS_QTY'].'" );' ."\n";
    }
    echo 'pageTracker._trackTrans();' ."\n";
}
?>
    } catch(err) {}</script>