// Added configuration checks to the Google Analytics modules
// Implemented the first real data in the dashboard
This commit is contained in:
@@ -54,23 +54,45 @@ class Dashtrends extends Module
|
||||
|
||||
public function hookDashboardDatas($params)
|
||||
{
|
||||
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
|
||||
if (Validate::isLoadedObject($gapi))
|
||||
{
|
||||
$visits_score = 0;
|
||||
if ($result = $gapi->requestReportData('', 'ga:visits', $this->context->employee->stats_date_from, $this->context->employee->stats_date_to, null, null, 1, 1))
|
||||
$visits_score = $result[0]['metrics']['visits'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$visits_score = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(c.`id_connections`)
|
||||
FROM `'._DB_PREFIX_.'connections` c
|
||||
WHERE c.`date_add` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.Shop::addSqlRestriction(false, 'c'));
|
||||
}
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT COUNT(o.`id_order`) as orders_score, SUM(o.`total_paid_tax_excl` / o.conversion_rate) as sales_score
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o'));
|
||||
extract($row);
|
||||
|
||||
return array(
|
||||
'data_value' => array(
|
||||
'sales_score' => Tools::displayPrice(151.365),
|
||||
'orders_score' => 120,
|
||||
'cart_value_score' => Tools::displayPrice(35),
|
||||
'visits_score' => 12,
|
||||
'convertion_rate_score' => 4,
|
||||
'net_profits_score' => Tools::displayPrice(42),
|
||||
),
|
||||
'sales_score' => Tools::displayPrice((float)$sales_score),
|
||||
'orders_score' => $orders_score,
|
||||
'cart_value_score' => Tools::displayPrice($orders_score ? $sales_score / $orders_score : 0),
|
||||
'visits_score' => $visits_score,
|
||||
'convertion_rate_score' => $visits_score ? 100 * $orders_score / $visits_score : 0,
|
||||
'net_profits_score' => Tools::displayPrice(0),
|
||||
),
|
||||
'data_trends' => array(
|
||||
'sales_score_trends' => array('way' => 'up', 'value' => 0.66),
|
||||
'orders_score_trends' => array('way' => 'down', 'value' => 0.66),
|
||||
'cart_value_score_trends' => array('way' => 'up', 'value' => 0.66),
|
||||
'visits_score_trends' => array('way' => 'down', 'value' => 0.66),
|
||||
'convertion_rate_score_trends' => array('way' => 'up', 'value' => 0.66),
|
||||
'net_profits_score_trends' => array('way' => 'up', 'value' => 0.66)
|
||||
)
|
||||
);
|
||||
'sales_score_trends' => array('way' => 'up', 'value' => 0.42),
|
||||
'orders_score_trends' => array('way' => 'down', 'value' => 0.42),
|
||||
'cart_value_score_trends' => array('way' => 'up', 'value' => 0.42),
|
||||
'visits_score_trends' => array('way' => 'down', 'value' => 0.42),
|
||||
'convertion_rate_score_trends' => array('way' => 'up', 'value' => 0.42),
|
||||
'net_profits_score_trends' => array('way' => 'up', 'value' => 0.42)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,28 @@ class Gapi extends Module
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$html = '';
|
||||
|
||||
// Check configuration
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
$openssl = extension_loaded('openssl');
|
||||
$curl = extension_loaded('curl');
|
||||
$ping = (($allow_url_fopen || $curl) && $openssl && Tools::file_get_contents('https://www.google.com/'));
|
||||
$online = (in_array(Tools::getRemoteAddr(), array('127.0.0.1', '::1')) ? false : true);
|
||||
|
||||
if (!$ping || !$online)
|
||||
{
|
||||
$html .= $this->displayError('<ul>
|
||||
'.(($curl && $allow_url_fopen) ? '' : '<li>'.$this->l('You are not allowed to open external URLs').'</li>').'
|
||||
'.(($curl && $allow_url_fopen) ? '' : '<li>'.$this->l('cURL is not enabled').'</li>').'
|
||||
'.($openssl ? '' : '<li>'.$this->l('OpenSSL is not enabled').'</li>').'
|
||||
'.(($allow_url_fopen AND $openssl AND !$ping) ? '<li>'.$this->l('Google is unreachable').' ('.$this->l('check your firewall').')</li>' : '').'
|
||||
'.($online ? '' : '<li>'.$this->l('Your store is not online').'</li>').'
|
||||
</ul>');
|
||||
}
|
||||
|
||||
// You can switch to the 1.3 API by replacing the following function call by $this->api_1_3_getContent()
|
||||
return $this->api_3_0_getContent();
|
||||
return $html.$this->api_3_0_getContent();
|
||||
}
|
||||
|
||||
public function requestReportData($dimensions, $metrics, $date_from, $date_to, $sort = null, $filters = null, $start = 1, $limit = 30)
|
||||
@@ -207,7 +227,6 @@ class Gapi extends Module
|
||||
$fields_options = array(
|
||||
'general' => array(
|
||||
'title' => $this->l('Google Analytics API v3.0'),
|
||||
'icon' => $this->_path.'logo.png',
|
||||
'fields' => $fields = array(
|
||||
'PS_GAPI30_CLIENT_ID' => array(
|
||||
'title' => $this->l('Client ID'),
|
||||
@@ -219,8 +238,7 @@ class Gapi extends Module
|
||||
),
|
||||
'PS_GAPI30_PROFILE' => array(
|
||||
'title' => $this->l('Profile'),
|
||||
'type' => 'text',
|
||||
'desc' => sprintf($this->l('You can find your profile ID in the address bar of your browser while accessing Analytics report: %s.'), '<a href="'.$this->_path.'screenshot.png'.'">'.$this->l('see screenshot').'</a>')
|
||||
'type' => 'text'
|
||||
)
|
||||
),
|
||||
'submit' => array('title' => $this->l('Save and Authenticate')),
|
||||
@@ -345,26 +363,22 @@ class Gapi extends Module
|
||||
$fields_options = array(
|
||||
'general' => array(
|
||||
'title' => $this->l('Google Analytics API v1.3'),
|
||||
'icon' => $this->_path.'logo.png',
|
||||
'fields' => $fields = array(
|
||||
'PS_GAPI13_EMAIL' => array(
|
||||
'title' => $this->l('Email'),
|
||||
'validation' => 'isEmail',
|
||||
'type' => 'text'
|
||||
),
|
||||
'PS_GAPI13_PASSWORD' => array(
|
||||
'title' => $this->l('Password'),
|
||||
'validation' => 'isNothing',
|
||||
'type' => 'password'
|
||||
),
|
||||
'PS_GAPI13_PROFILE' => array(
|
||||
'title' => $this->l('Profile'),
|
||||
'validation' => 'isUnsignedInt',
|
||||
'type' => 'text',
|
||||
'desc' => sprintf($this->l('You can find your profile ID in the address bar of your browser while accessing Analytics report: %s.'), '<a href="'.$this->_path.'screenshot.png'.'">'.$this->l('see screenshot').'</a>')
|
||||
'desc' => $this->l('You can find your profile ID in the address bar of your browser while accessing Analytics report.')
|
||||
)
|
||||
),
|
||||
'submit' => array('title' => $this->l('Authenticate'), 'class' => 'button'),
|
||||
'submit' => array('title' => $this->l('Save and Authenticate')),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user