diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-04-03 23:45:01 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-04-03 23:45:01 +0400 |
commit | 02cf8c55b94e31ddc14240a4d0bbbacb576631a8 (patch) | |
tree | 0ba1a8e6d09c556233d875cbb4efd27a9964a4ad /plugins | |
parent | a12cf721b04e22eb3a8d3c0d82397687faa34aed (diff) | |
parent | 34da04edb32b0029f2bd261c8911a735c7cf3c11 (diff) |
Merge branch 'master' of github.com:piwik/piwik
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreConsole/Commands/CoreArchiver.php | 4 | ||||
-rw-r--r-- | plugins/Goals/Controller.php | 2 | ||||
-rw-r--r-- | plugins/VisitFrequency/API.php | 123 | ||||
-rw-r--r-- | plugins/VisitFrequency/Archiver.php | 131 |
4 files changed, 53 insertions, 207 deletions
diff --git a/plugins/CoreConsole/Commands/CoreArchiver.php b/plugins/CoreConsole/Commands/CoreArchiver.php index eae8d80f51..0fe60d3bc9 100644 --- a/plugins/CoreConsole/Commands/CoreArchiver.php +++ b/plugins/CoreConsole/Commands/CoreArchiver.php @@ -46,8 +46,8 @@ class CoreArchiver extends ConsoleCommand $command->addOption('force-all-periods', null, InputOption::VALUE_OPTIONAL, "Limits archiving to websites with some traffic in the last [seconds] seconds. \nFor example --force-all-periods=86400 will archive websites that had visits in the last 24 hours. \nIf [seconds] is not specified, all websites with visits in the last " . CronArchive::ARCHIVE_SITES_WITH_TRAFFIC_SINCE . "\n seconds (" . round(CronArchive::ARCHIVE_SITES_WITH_TRAFFIC_SINCE / 86400) . " days) will be archived."); $command->addOption('force-timeout-for-periods', null, InputOption::VALUE_OPTIONAL, "The current week/ current month/ current year will be processed at most every [seconds].\nIf not specified, defaults to " . CronArchive::SECONDS_DELAY_BETWEEN_PERIOD_ARCHIVES . "."); $command->addOption('force-date-last-n', null, InputOption::VALUE_REQUIRED, "This script calls the API with period=lastN. You can force the N in lastN by specifying this value."); - $command->addOption("force-idsites", null, InputOption::VALUE_OPTIONAL, 'If specified, archiving will be processed only for these Sites Ids (comma separated)'); - $command->addOption("skip-idsites", null, InputOption::VALUE_OPTIONAL, 'If specified, archiving will be skipped for these websites (in case these website ids would have been archived).'); + $command->addOption('force-idsites', null, InputOption::VALUE_OPTIONAL, 'If specified, archiving will be processed only for these Sites Ids (comma separated)'); + $command->addOption('skip-idsites', null, InputOption::VALUE_OPTIONAL, 'If specified, archiving will be skipped for these websites (in case these website ids would have been archived).'); $command->addOption('disable-scheduled-tasks', null, InputOption::VALUE_NONE, "Skips executing Scheduled tasks (sending scheduled reports, db optimization, etc.)."); $command->addOption('xhprof', null, InputOption::VALUE_NONE, "Enables XHProf profiler for this archive.php run. Requires XHPRof (see tests/README.xhprof.md)."); $command->addOption('accept-invalid-ssl-certificate', null, InputOption::VALUE_NONE, "It is _NOT_ recommended to use this argument. Instead, you should use a valid SSL certificate!\nIt can be useful if you specified --url=https://... or if you are using Piwik with force_ssl=1"); diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index ba8a68efed..2d64135948 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -145,7 +145,7 @@ class Controller extends \Piwik\Plugin\Controller $view->topDimensions = $this->getTopDimensions($idGoal); // conversion rate for new and returning visitors - $segment = urldecode(\Piwik\Plugins\VisitFrequency\Archiver::RETURNING_VISITOR_SEGMENT); + $segment = urldecode(\Piwik\Plugins\VisitFrequency\API::RETURNING_VISITOR_SEGMENT); $conversionRateReturning = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_returning = $this->formatConversionRate($conversionRateReturning); $segment = 'visitorType==new'; diff --git a/plugins/VisitFrequency/API.php b/plugins/VisitFrequency/API.php index 4c0f724398..e837fee01d 100644 --- a/plugins/VisitFrequency/API.php +++ b/plugins/VisitFrequency/API.php @@ -15,6 +15,7 @@ use Piwik\Common; use Piwik\Archive; use Piwik\SegmentExpression; use Piwik\SettingsPiwik; +use Piwik\Plugins\VisitsSummary\API as APIVisitsSummary; /** * VisitFrequency API lets you access a list of metrics related to Returning Visitors. @@ -22,86 +23,62 @@ use Piwik\SettingsPiwik; */ class API extends \Piwik\Plugin\API { + // visitorType==returning,visitorType==returningCustomer + const RETURNING_VISITOR_SEGMENT = "visitorType%3D%3Dreturning%2CvisitorType%3D%3DreturningCustomer"; + const COLUMN_SUFFIX = "_returning"; + + /** + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @param bool|array $columns + * @return mixed + */ public function get($idSite, $period, $date, $segment = false, $columns = false) { - $archive = Archive::build($idSite, $period, $date, $segment); - - // array values are comma separated - $columns = Piwik::getArrayFromApiParameter($columns); - $tempColumns = array(); - - $bounceRateReturningRequested = $averageVisitDurationReturningRequested = $actionsPerVisitReturningRequested = false; - if (!empty($columns)) { - // make sure base metrics are there for processed metrics - if (false !== ($bounceRateReturningRequested = array_search('bounce_rate_returning', $columns))) { - if (!in_array('nb_visits_returning', $columns)) { - $tempColumns[] = 'nb_visits_returning'; - } - - if (!in_array('bounce_count_returning', $columns)) { - $tempColumns[] = 'bounce_count_returning'; - } - - unset($columns[$bounceRateReturningRequested]); - } - - if (false !== ($actionsPerVisitReturningRequested = array_search('nb_actions_per_visit_returning', $columns))) { - if (!in_array('nb_actions_returning', $columns)) { - $tempColumns[] = 'nb_actions_returning'; - } - - if (!in_array('nb_visits_returning', $columns)) { - $tempColumns[] = 'nb_visits_returning'; - } - - unset($columns[$actionsPerVisitReturningRequested]); - } - - if (false !== ($averageVisitDurationReturningRequested = array_search('avg_time_on_site_returning', $columns))) { - if (!in_array('sum_visit_length_returning', $columns)) { - $tempColumns[] = 'sum_visit_length_returning'; - } - - if (!in_array('nb_visits_returning', $columns)) { - $tempColumns[] = 'nb_visits_returning'; - } - - unset($columns[$averageVisitDurationReturningRequested]); - } + $segment = $this->appendReturningVisitorSegment($segment); + + $this->unprefixColumns($columns); + $params = array( + 'idSite' => $idSite, + 'period' => $period, + 'date' => $date, + 'segment' => $segment, + 'columns' => implode(',', $columns), + 'format' => 'original', + 'serialize' => 0 // tests set this to 1 + ); + $table = Request::processRequest('VisitsSummary.get', $params); + $this->prefixColumns($table, $period); + return $table; + } - $tempColumns = array_unique($tempColumns); - $columns = array_merge($columns, $tempColumns); + protected function appendReturningVisitorSegment($segment) + { + if (empty($segment)) { + $segment = ''; } else { - $bounceRateReturningRequested = $averageVisitDurationReturningRequested = $actionsPerVisitReturningRequested = true; - $columns = array( - 'nb_visits_returning', - 'nb_actions_returning', - 'nb_visits_converted_returning', - 'bounce_count_returning', - 'sum_visit_length_returning', - 'max_actions_returning', - ); - - if (SettingsPiwik::isUniqueVisitorsEnabled($period)) { - $columns = array_merge(array('nb_uniq_visitors_returning'), $columns); - } + $segment .= urlencode(SegmentExpression::AND_DELIMITER); } - $dataTable = $archive->getDataTableFromNumeric($columns); + $segment .= self::RETURNING_VISITOR_SEGMENT; + return $segment; + } - // Process ratio metrics - if ($bounceRateReturningRequested !== false) { - $dataTable->filter('ColumnCallbackAddColumnPercentage', array('bounce_rate_returning', 'bounce_count_returning', 'nb_visits_returning', 0)); - } - if ($actionsPerVisitReturningRequested !== false) { - $dataTable->filter('ColumnCallbackAddColumnQuotient', array('nb_actions_per_visit_returning', 'nb_actions_returning', 'nb_visits_returning', 1)); - } - if ($averageVisitDurationReturningRequested !== false) { - $dataTable->filter('ColumnCallbackAddColumnQuotient', array('avg_time_on_site_returning', 'sum_visit_length_returning', 'nb_visits_returning', 0)); + protected function unprefixColumns(&$columns) + { + $columns = Piwik::getArrayFromApiParameter($columns); + foreach ($columns as &$column) { + $column = str_replace(self::COLUMN_SUFFIX, "", $column); } + } - // remove temporary metrics that were used to compute processed metrics - $dataTable->deleteColumns($tempColumns); - - return $dataTable; + protected function prefixColumns($table, $period) + { + $rename = array(); + foreach (APIVisitsSummary::getInstance()->getColumns($period) as $oldColumn) { + $rename[$oldColumn] = $oldColumn . self::COLUMN_SUFFIX; + } + $table->filter('ReplaceColumnNames', array($rename)); } }
\ No newline at end of file diff --git a/plugins/VisitFrequency/Archiver.php b/plugins/VisitFrequency/Archiver.php deleted file mode 100644 index b6f9913346..0000000000 --- a/plugins/VisitFrequency/Archiver.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -namespace Piwik\Plugins\VisitFrequency; - -use Piwik\ArchiveProcessor; -use Piwik\ArchiveProcessor\Parameters as ArchiveProcessorParams; -use Piwik\DataAccess\LogAggregator; -use Piwik\API\Request; -use Piwik\Piwik; -use Piwik\Segment; -use Piwik\SegmentExpression; -use Piwik\Plugins\VisitsSummary\API as APIVisitsSummary; -use Piwik\SettingsPiwik; -use Piwik\Metrics; - -/** - * Introduced to provide backwards compatibility for pre-2.0 data. Uses a segment to archive - * data for day periods and aggregates this data for non-day periods. - * - * We normally would want to just forward requests to the VisitsSummary API w/ the correctly - * modified segment, but in order to combine pre-2.0 data with post-2.0 data, there has - * to be a VisitFrequency Archiver. Otherwise, the VisitsSummary metrics archiving will - * be called, and the pre-2.0 VisitFrequency data (which is not retrieved by VisitsSummary) will - * be ignored. - */ -class Archiver extends \Piwik\Plugin\Archiver -{ - // visitorType==returning,visitorType==returningCustomer - const RETURNING_VISITOR_SEGMENT = "visitorType%3D%3Dreturning%2CvisitorType%3D%3DreturningCustomer"; - const COLUMN_SUFFIX = "_returning"; - - public static $visitFrequencyPeriodMetrics = array( - 'nb_visits_returning', - 'nb_actions_returning', - 'max_actions_returning', - 'sum_visit_length_returning', - 'bounce_count_returning', - 'nb_visits_converted_returning' - ); - - public function aggregateDayReport() - { - $this->callVisitsSummaryApiAndArchive(); - } - - public function aggregateMultipleReports() - { - if (SettingsPiwik::isUniqueVisitorsEnabled($this->getProcessor()->getParams()->getPeriod()->getLabel())) { - $this->computeUniqueVisitsForNonDay(); - } - - $this->getProcessor()->aggregateNumericMetrics(self::$visitFrequencyPeriodMetrics); - } - - private function callVisitsSummaryApiAndArchive($columns = false) - { - $archiveParams = $this->getProcessor()->getParams(); - $periodLabel = $archiveParams->getPeriod()->getLabel(); - - $params = array( - 'idSite' => $archiveParams->getSite()->getId(), - 'period' => $periodLabel, - 'date' => $archiveParams->getPeriod()->getDateStart()->toString(), - 'segment' => $this->appendReturningVisitorSegment($archiveParams->getSegment()->getString()), - 'format' => 'original', - 'serialize' => 0 // make sure we don't serialize (in case serialize is in the query parameters) - ); - if ($columns) { - $params['columns'] = implode(",", $columns); - } - - $table = Request::processRequest('VisitsSummary.get', $params); - $this->suffixColumns($table, $periodLabel); - - if ($table->getRowsCount() > 0) { - $this->getProcessor()->insertNumericRecords($table->getFirstRow()->getColumns()); - } - } - - private function computeUniqueVisitsForNonDay() - { - // NOTE: we cannot call the VisitsSummary API from within period archiving for some reason. it results in - // a very hard to trace bug that breaks the OmniFixture severely (causes lots of data to not be shown). - // no idea why it causes such an error. - $oldParams = $this->getProcessor()->getParams(); - $site = $oldParams->getSite(); - $newSegment = $this->appendReturningVisitorSegment($oldParams->getSegment()->getString()); - $newParams = new ArchiveProcessorParams($site, $oldParams->getPeriod(), new Segment($newSegment, array($site->getId()))); - - $logAggregator = new LogAggregator($newParams); - $query = $logAggregator->queryVisitsByDimension(array(), false, array(), array(Metrics::INDEX_NB_UNIQ_VISITORS)); - $data = $query->fetch(); - $nbUniqVisitors = (float)$data[Metrics::INDEX_NB_UNIQ_VISITORS]; - - $this->getProcessor()->insertNumericRecord('nb_uniq_visitors_returning', $nbUniqVisitors); - } - - protected function appendReturningVisitorSegment($segment) - { - if (empty($segment)) { - $segment = ''; - } else { - $segment .= urlencode(SegmentExpression::AND_DELIMITER); - } - $segment .= self::RETURNING_VISITOR_SEGMENT; - return $segment; - } - - protected function unsuffixColumns(&$columns) - { - $columns = Piwik::getArrayFromApiParameter($columns); - foreach ($columns as &$column) { - $column = str_replace(self::COLUMN_SUFFIX, "", $column); - } - } - - protected function suffixColumns($table, $period) - { - $rename = array(); - foreach (APIVisitsSummary::getInstance()->getColumns($period) as $oldColumn) { - $rename[$oldColumn] = $oldColumn . self::COLUMN_SUFFIX; - } - $table->filter('ReplaceColumnNames', array($rename)); - } -}
\ No newline at end of file |