diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2011-10-27 07:42:04 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2011-10-27 07:42:04 +0400 |
commit | d93063bd7322597b80d73b06b835aa466f74da18 (patch) | |
tree | ef1a0ecbc29d8c793a784d6abb14ec8a9c905f32 /plugins/VisitorInterest/API.php | |
parent | a04d8c8d6ae0c8cca7e678eb9a332c14e085b6df (diff) |
Fixes #584, #536, #2031 - Kuddos to Benaka akka capedfuzz for this great patch!!! I did a few minor modifications in wording and metadata output
* Add Report "Visits by visit number" under Visitors > Engagement
* Add Report for all Goals (including ecommerce): "Visit until Conversion": number of visits until the conversion occured
* Add Report for all Goals (including ecommerce): "Days until Conversion": days since the first visit
Notes
* These new reports are also in the Metadata API so should be displayed in Piwik Mobile, and can be exported in the Scheduled reports.
* filter_only_idgoal now renamed as idGoal for consistency
* refactored the "Beautify labels" for ranges in generic filters
* refactored archiving code to process multiple reports in one generic SQL query
git-svn-id: http://dev.piwik.org/svn/trunk@5378 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/VisitorInterest/API.php')
-rw-r--r-- | plugins/VisitorInterest/API.php | 100 |
1 files changed, 49 insertions, 51 deletions
diff --git a/plugins/VisitorInterest/API.php b/plugins/VisitorInterest/API.php index 512c766027..7f23f4f56d 100644 --- a/plugins/VisitorInterest/API.php +++ b/plugins/VisitorInterest/API.php @@ -28,12 +28,12 @@ class Piwik_VisitorInterest_API return self::$instance; } - protected function getDataTable($name, $idSite, $period, $date, $segment) + protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Piwik_Archive::INDEX_NB_VISITS) { Piwik::checkUserHasViewAccess( $idSite ); $archive = Piwik_Archive::build($idSite, $period, $date, $segment ); $dataTable = $archive->getDataTable($name); - $dataTable->filter('Sort',array(Piwik_Archive::INDEX_NB_VISITS)); + $dataTable->filter('Sort',array($column)); $dataTable->queueFilter('ReplaceColumnNames'); $dataTable->queueFilter('Sort', array('label', 'asc', true)); return $dataTable; @@ -42,69 +42,67 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsPerVisitDuration( $idSite, $period, $date, $segment = false ) { $dataTable = $this->getDataTable('VisitorInterest_timeGap', $idSite, $period, $date, $segment); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getDurationLabel')); + $dataTable->queueFilter('BeautifyTimeRangeLabels', array( + Piwik_Translate('VisitorInterest_BetweenXYSeconds'), + Piwik_Translate('VisitorInterest_OneMinute'), + Piwik_Translate('VisitorInterest_PlusXMin'))); return $dataTable; } public function getNumberOfVisitsPerPage( $idSite, $period, $date, $segment = false ) { $dataTable = $this->getDataTable('VisitorInterest_pageGap', $idSite, $period, $date, $segment); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getPageGapLabel')); + $dataTable->queueFilter('BeautifyRangeLabels', array( + Piwik_Translate('VisitorInterest_OnePage'), + Piwik_Translate('VisitorInterest_NPages'))); + return $dataTable; + } + + /** + * Returns a DataTable that associates ranges of visit numbers with the count of visits + * whose visit number falls within those ranges. + * + * @param int $idSite The site to select data from. + * @param string $period The period type. + * @param string $date The date type. + * @param string|bool $segment The segment. + * @return Piwik_DataTable the archived report data. + */ + public function getNumberOfVisitsByVisitCount( $idSite, $period, $date, $segment = false ) + { + $dataTable = $this->getDataTable( + 'VisitorInterest_visitsByVisitCount', $idSite, $period, $date, $segment, Piwik_Archive::INDEX_NB_VISITS); + + $dataTable->queueFilter('BeautifyRangeLabels', array( + Piwik_Translate('General_OneVisit'), Piwik_Translate('General_NVisits'))); + + // add visit percent column + self::addVisitsPercentColumn($dataTable); + return $dataTable; } -} -function Piwik_getDurationLabel($label) -{ - if(($pos = strpos($label,'-')) !== false) + /** + * Utility function that adds a visit percent column to a data table, + * regardless of whether the data table is an data table array or just + * a data table. + * + * @param Piwik_DataTable $dataTable The data table to modify. + */ + private static function addVisitsPercentColumn( $dataTable ) { - $min = substr($label, 0, $pos); - $max = substr($label, $pos+1); - - if($min == 0 || $min == 30) + if ($dataTable instanceof Piwik_DataTable_Array) { - $XYSeconds = Piwik_Translate('VisitorInterest_BetweenXYSeconds'); - return sprintf($XYSeconds, $min, $max); + foreach($dataTable->getArray() as $table) + { + self::addVisitsPercentColumn($table); + } } else { - $min = $min / 60; - $max = $max / 60; - $XYMin = Piwik_Translate('VisitorInterest_BetweenXYMinutes'); - return sprintf($XYMin, $min, $max); + $totalVisits = array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS)); + $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array( + 'nb_visits_percentage', 'nb_visits', $totalVisits)); } } - if(!is_numeric($label)) - { - return $label; - } - $time = intval($label) / 60; - $plusXMin = Piwik_Translate('VisitorInterest_PlusXMin'); - return sprintf($plusXMin, $time . urlencode('+')); -} - -function Piwik_getPageGapLabel($label) -{ - $return = false; - if(($pos = strpos($label,'-')) !== false) - { - $min = substr($label, 0, $pos); - $max = substr($label, $pos+1); - - if($min == $max) - { - $return = $min; - } - } - if(!$return) - { - $return = $label; - } - - if($return == 1) - { - return Piwik_Translate('VisitorInterest_OnePage'); - } - - return sprintf(Piwik_Translate('VisitorInterest_NPages'), $return); } |