* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class StatsData extends Module { public function __construct() { $this->name = 'statsdata'; $this->tab = 'analytics_stats'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Data mining for statistics'); $this->description = $this->l('This module must be enabled if you want to use Statistics.'); } public function install() { return (parent::install() AND $this->registerHook('footer') AND $this->registerHook('authentication') AND $this->registerHook('createAccount')); } public function getContent() { if (Tools::isSubmit('submitStatsData')) { Configuration::updateValue('PS_STATSDATA_CUSTOMER_PAGESVIEWS', (int)Tools::getValue('PS_STATSDATA_CUSTOMER_PAGESVIEWS')); Configuration::updateValue('PS_STATSDATA_PAGESVIEWS', (int)Tools::getValue('PS_STATSDATA_PAGESVIEWS')); Configuration::updateValue('PS_STATSDATA_PLUGINS', (int)Tools::getValue('PS_STATSDATA_PLUGINS')); echo '
'.$this->l('Configuration updated').'
'; } return '
'.$this->l('Settings').'

'.$this->l('Customer page views uses a lot of CPU resources and database space.').'

 

'.$this->l('Global page views uses less resources than customer\'s, but uses resources nonetheless.').'

 

'.$this->l('Plug-ins detection loads an extra 20kb javascript file for new visitors.').'

 
'; } public function hookFooter($params) { $html = ''; if (!isset($params['cookie']->id_guest)) { Guest::setNewGuest($params['cookie']); if (Configuration::get('PS_STATSDATA_PLUGINS')) { // Ajax request sending browser information $token = sha1($params['cookie']->id_guest._COOKIE_KEY_); $html .= ' '; } } // Record the guest path then increment the visit counter of the page $tokenArray = Connection::setPageConnection($params['cookie']); ConnectionsSource::logHttpReferer(); if (Configuration::get('PS_STATSDATA_PAGESVIEWS')) Page::setPageViewed($tokenArray['id_page']); if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS')) { // Ajax request sending the time spend on the page $token = sha1($tokenArray['id_connections'].$tokenArray['id_page'].$tokenArray['time_start']._COOKIE_KEY_); $html .= ' '; } return $html; } public function hookCreateAccount($params) { return $this->hookAuthentication($params); } public function hookAuthentication($params) { // Update or merge the guest with the customer id (login and account creation) $guest = new Guest($params['cookie']->id_guest); $result = Db::getInstance()->getRow(' SELECT `id_guest` FROM `'._DB_PREFIX_.'guest` WHERE `id_customer` = '.(int)($params['cookie']->id_customer)); if ((int)($result['id_guest'])) { // The new guest is merged with the old one when it's connecting to an account $guest->mergeWithCustomer($result['id_guest'], $params['cookie']->id_customer); $params['cookie']->id_guest = $guest->id; } else { // The guest is duplicated if it has multiple customer accounts $method = ($guest->id_customer) ? 'add' : 'update'; $guest->id_customer = $params['cookie']->id_customer; $guest->{$method}(); } } }