// Added realtime Analytics to the dashboard (private beta only at this time)
This commit is contained in:
1 parent
937ce38a1f
commit
981ce70594
2 files changed
+25
-22
No files matched your search
@@ -79,12 +79,14 @@ class Dashactivity extends Module
|
|||||||
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
|
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
|
||||||
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
|
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
|
||||||
{
|
{
|
||||||
$visits = $unique_visitors = 0;
|
$visits = $unique_visitors = $online_visitors = 0;
|
||||||
if ($result = $gapi->requestReportData('', 'ga:visits,ga:visitors', $params['date_from'], $params['date_to'], null, null, 1, 1))
|
if ($result = $gapi->requestReportData('', 'ga:visits,ga:visitors', $params['date_from'], $params['date_to'], null, null, 1, 1))
|
||||||
{
|
{
|
||||||
$visits = $result[0]['metrics']['visits'];
|
$visits = $result[0]['metrics']['visits'];
|
||||||
$unique_visitors = $result[0]['metrics']['visitors'];
|
$unique_visitors = $result[0]['metrics']['visitors'];
|
||||||
}
|
}
|
||||||
|
if ($result = $gapi->requestReportData('', 'ga:activeVisitors', null, null, null, null, 1, 1))
|
||||||
|
$online_visitors = $result[0]['metrics']['activeVisitors'];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -94,6 +96,24 @@ class Dashactivity extends Module
|
|||||||
WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
|
WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
|
||||||
'.Shop::addSqlRestriction(false));
|
'.Shop::addSqlRestriction(false));
|
||||||
extract($row);
|
extract($row);
|
||||||
|
|
||||||
|
if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP'))
|
||||||
|
$maintenance_ips = implode(',', array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))));
|
||||||
|
if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
|
||||||
|
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
|
||||||
|
FROM `'._DB_PREFIX_.'connections` c
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
|
||||||
|
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
|
||||||
|
AND cp.`time_end` IS NULL
|
||||||
|
'.Shop::addSqlRestriction(false, 'c').'
|
||||||
|
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
|
||||||
|
else
|
||||||
|
$sql = 'SELECT COUNT(*)
|
||||||
|
FROM `'._DB_PREFIX_.'connections`
|
||||||
|
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
|
||||||
|
'.Shop::addSqlRestriction(false).'
|
||||||
|
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
|
||||||
|
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$order_nbr = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
$order_nbr = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
@@ -129,25 +149,7 @@ class Dashactivity extends Module
|
|||||||
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON ct.id_customer_thread = cm.id_customer_thread
|
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON ct.id_customer_thread = cm.id_customer_thread
|
||||||
WHERE cm.`date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
|
WHERE cm.`date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
|
||||||
'.Shop::addSqlRestriction(false, 'ct'));
|
'.Shop::addSqlRestriction(false, 'ct'));
|
||||||
|
|
||||||
if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP'))
|
|
||||||
$maintenance_ips = implode(',', array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))));
|
|
||||||
if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
|
|
||||||
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
|
|
||||||
FROM `'._DB_PREFIX_.'connections` c
|
|
||||||
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
|
|
||||||
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
|
|
||||||
AND cp.`time_end` IS NULL
|
|
||||||
'.Shop::addSqlRestriction(false, 'c').'
|
|
||||||
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
|
|
||||||
else
|
|
||||||
$sql = 'SELECT COUNT(*)
|
|
||||||
FROM `'._DB_PREFIX_.'connections`
|
|
||||||
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
|
|
||||||
'.Shop::addSqlRestriction(false).'
|
|
||||||
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
|
|
||||||
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
|
||||||
|
|
||||||
$active_shopping_cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
$active_shopping_cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM `'._DB_PREFIX_.'cart`
|
FROM `'._DB_PREFIX_.'cart`
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class Gapi extends Module
|
|||||||
return $html.$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)
|
public function requestReportData($dimensions, $metrics, $date_from = null, $date_to = null, $sort = null, $filters = null, $start = 1, $limit = 30)
|
||||||
{
|
{
|
||||||
// You can switch to the 1.3 API by replacing the following function call by $this->api_1_3_requestReportData()
|
// You can switch to the 1.3 API by replacing the following function call by $this->api_1_3_requestReportData()
|
||||||
return $this->api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit);
|
return $this->api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit);
|
||||||
@@ -326,7 +326,8 @@ class Gapi extends Module
|
|||||||
'timeout' => 5,
|
'timeout' => 5,
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
if (!$response_json = Tools::file_get_contents('https://www.googleapis.com/analytics/v3/data/ga?'.$content, false, $stream_context))
|
$api = ($date_from && $date_to) ? 'ga' : 'realtime';
|
||||||
|
if (!$response_json = Tools::file_get_contents('https://www.googleapis.com/analytics/v3/data/'.$api.'?'.$content, false, $stream_context))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// https://developers.google.com/analytics/devguides/reporting/core/v3/reference
|
// https://developers.google.com/analytics/devguides/reporting/core/v3/reference
|
||||||
|
|||||||
Reference in new issue
Block a user