Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2011-02-12 16:34:53 +0300
committermattpiwik <matthieu.aubry@gmail.com>2011-02-12 16:34:53 +0300
commit0e3252517cf23823cbb231250ab1839679ae6808 (patch)
tree3296cadc2ee9f6b939034b9d26d39f0ad83b362f /plugins/UserCountry
parent8518cb19b351e5d9be1d6d1951da4a8f0044cb96 (diff)
Refs #1736
* API functions returning data now have a new optional 'segment' parameter. segment can define a Visitor segment dynamically that will be applied to the report. For example, &segment=country==FR;actions>=3 (AND, OR supported. Only == and != supported currently, but easy to add more) * For API requests with a segment parameter, the reports will now be processed on the fly, and only the requested plugin report will be archived. * All plugins now define the 'segments', with a name, category, SQL field, filter, etc. * Simplifying archiving code a bit * Fixes #2069 Exit rate computation * New widget: lists the Top Keywords for a page URL, Widgets for a website only. Maybe later we could create a widget category "For your site"? * This widget is pretty cool SEO wise, but maybe the PHP snippet should do caching (not so good hitting the API on each page view... but why not?) * still to do! git-svn-id: http://dev.piwik.org/svn/trunk@3870 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/UserCountry')
-rw-r--r--plugins/UserCountry/API.php16
-rw-r--r--plugins/UserCountry/UserCountry.php54
2 files changed, 51 insertions, 19 deletions
diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php
index cdab67c89e..4cfe49763c 100644
--- a/plugins/UserCountry/API.php
+++ b/plugins/UserCountry/API.php
@@ -33,9 +33,9 @@ class Piwik_UserCountry_API
return self::$instance;
}
- public function getCountry( $idSite, $period, $date )
+ public function getCountry( $idSite, $period, $date, $segment = false )
{
- $dataTable = $this->getDataTable('UserCountry_country', $idSite, $period, $date);
+ $dataTable = $this->getDataTable('UserCountry_country', $idSite, $period, $date, $segment);
// apply filter on the whole datatable in order the inline search to work (searches are done on "beautiful" label)
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'code', create_function('$label', 'return $label;')));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getFlagFromCode'));
@@ -45,28 +45,28 @@ class Piwik_UserCountry_API
return $dataTable;
}
- public function getContinent( $idSite, $period, $date )
+ public function getContinent( $idSite, $period, $date, $segment = false )
{
- $dataTable = $this->getDataTable('UserCountry_continent', $idSite, $period, $date);
+ $dataTable = $this->getDataTable('UserCountry_continent', $idSite, $period, $date, $segment);
$dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_ContinentTranslate'));
$dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'code', create_function('$label', 'return $label;')));
return $dataTable;
}
- protected function getDataTable($name, $idSite, $period, $date)
+ protected function getDataTable($name, $idSite, $period, $date, $segment)
{
Piwik::checkUserHasViewAccess( $idSite );
- $archive = Piwik_Archive::build($idSite, $period, $date );
+ $archive = Piwik_Archive::build($idSite, $period, $date, $segment );
$dataTable = $archive->getDataTable($name);
$dataTable->filter('Sort', array(Piwik_Archive::INDEX_NB_VISITS));
$dataTable->queueFilter('ReplaceColumnNames');
return $dataTable;
}
- public function getNumberOfDistinctCountries($idSite, $period, $date)
+ public function getNumberOfDistinctCountries($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess( $idSite );
- $archive = Piwik_Archive::build($idSite, $period, $date );
+ $archive = Piwik_Archive::build($idSite, $period, $date, $segment );
return $archive->getDataTableFromNumeric('UserCountry_distinctCountries');
}
}
diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php
index 226fe80026..db8d80a541 100644
--- a/plugins/UserCountry/UserCountry.php
+++ b/plugins/UserCountry/UserCountry.php
@@ -36,10 +36,44 @@ class Piwik_UserCountry extends Piwik_Plugin
'Menu.add' => 'addMenu',
'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics',
'API.getReportMetadata' => 'getReportMetadata',
+ 'API.getSegmentsMetadata' => 'getSegmentsMetadata',
);
return $hooks;
}
+ function addWidgets()
+ {
+ Piwik_AddWidget( 'General_Visitors', 'UserCountry_WidgetContinents', 'UserCountry', 'getContinent');
+ Piwik_AddWidget( 'General_Visitors', 'UserCountry_WidgetCountries', 'UserCountry', 'getCountry');
+ }
+
+ function addMenu()
+ {
+ Piwik_AddMenu('General_Visitors', 'UserCountry_SubmenuLocations', array('module' => 'UserCountry', 'action' => 'index'));
+ }
+
+
+ public function getSegmentsMetadata($notification)
+ {
+ $segments =& $notification->getNotificationObject();
+ $segments[] = array(
+ 'type' => 'dimension',
+ 'category' => 'Visit',
+ 'name' => Piwik_Translate('UserCountry_Country'),
+ 'segment' => 'country',
+ 'sqlSegment' => 'location_country',
+ 'acceptedValues' => 'de, us, fr, in, es, etc.'
+ );
+ $segments[] = array(
+ 'type' => 'dimension',
+ 'category' => 'Visit',
+ 'name' => Piwik_Translate('UserCountry_Continent'),
+ 'segment' => 'continent',
+ 'sqlSegment' => 'location_continent',
+ 'acceptedValues' => 'eur, asi, amc, amn, ams, afr, ant, oce'
+ );
+ }
+
public function getReportMetadata($notification)
{
$reports = &$notification->getNotificationObject();
@@ -49,6 +83,7 @@ class Piwik_UserCountry extends Piwik_Plugin
'module' => 'UserCountry',
'action' => 'getCountry',
'dimension' => Piwik_Translate('UserCountry_Country'),
+ ''
);
$reports[] = array(
@@ -60,17 +95,6 @@ class Piwik_UserCountry extends Piwik_Plugin
);
}
- function addWidgets()
- {
- Piwik_AddWidget( 'General_Visitors', 'UserCountry_WidgetContinents', 'UserCountry', 'getContinent');
- Piwik_AddWidget( 'General_Visitors', 'UserCountry_WidgetCountries', 'UserCountry', 'getCountry');
- }
-
- function addMenu()
- {
- Piwik_AddMenu('General_Visitors', 'UserCountry_SubmenuLocations', array('module' => 'UserCountry', 'action' => 'index'));
- }
-
function getReportsWithGoalMetrics( $notification )
{
$dimensions =& $notification->getNotificationObject();
@@ -92,6 +116,8 @@ class Piwik_UserCountry extends Piwik_Plugin
{
$archiveProcessing = $notification->getNotificationObject();
+ if(!$archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) return;
+
$dataTableToSum = array(
'UserCountry_country',
'UserCountry_continent',
@@ -105,6 +131,9 @@ class Piwik_UserCountry extends Piwik_Plugin
function archiveDay($notification)
{
$archiveProcessing = $notification->getNotificationObject();
+
+ if(!$archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) return;
+
$this->archiveDayAggregateVisits($archiveProcessing);
$this->archiveDayAggregateGoals($archiveProcessing);
$this->archiveDayRecordInDatabase($archiveProcessing);
@@ -122,6 +151,9 @@ class Piwik_UserCountry extends Piwik_Plugin
protected function archiveDayAggregateGoals($archiveProcessing)
{
$query = $archiveProcessing->queryConversionsByDimension(array("location_continent","location_country"));
+
+ if($query === false) return;
+
while($row = $query->fetch() )
{
if(!isset($this->interestByCountry[$row['location_country']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) $this->interestByCountry[$row['location_country']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();