1<?php 2/** 3 * Matomo - free/libre analytics platform 4 * 5 * @link https://matomo.org 6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later 7 * 8 */ 9namespace Piwik\Plugins\Actions; 10 11use Piwik\Metrics as PiwikMetrics; 12use Piwik\Piwik; 13use Piwik\Tracker\Action; 14 15/** 16 * Class encapsulating logic to process Day/Period Archiving for the Actions reports 17 * 18 */ 19class Metrics 20{ 21 22 public static $actionTypes = array( 23 Action::TYPE_PAGE_URL, 24 Action::TYPE_OUTLINK, 25 Action::TYPE_DOWNLOAD, 26 Action::TYPE_PAGE_TITLE, 27 Action::TYPE_SITE_SEARCH, 28 ); 29 30 public static $columnsToRenameAfterAggregation = array( 31 PiwikMetrics::INDEX_NB_UNIQ_VISITORS => PiwikMetrics::INDEX_SUM_DAILY_NB_UNIQ_VISITORS, 32 PiwikMetrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS => PiwikMetrics::INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS, 33 PiwikMetrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS => PiwikMetrics::INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS, 34 ); 35 36 public static $columnsToDeleteAfterAggregation = array( 37 PiwikMetrics::INDEX_NB_UNIQ_VISITORS, 38 PiwikMetrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS, 39 PiwikMetrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS, 40 ); 41 42 public static $columnsAggregationOperation = array( 43 PiwikMetrics::INDEX_PAGE_MAX_TIME_GENERATION => 'max', 44 PiwikMetrics::INDEX_PAGE_MIN_TIME_GENERATION => 'min' 45 ); 46 47 public static function getActionMetrics() 48 { 49 $metricsConfig = array( 50 PiwikMetrics::INDEX_NB_VISITS => array( 51 'aggregation' => 'sum', 52 'query' => "count(distinct log_link_visit_action.idvisit)" 53 ), 54 PiwikMetrics::INDEX_NB_UNIQ_VISITORS => array( 55 'aggregation' => false, 56 'query' => "count(distinct log_link_visit_action.idvisitor)" 57 ), 58 PiwikMetrics::INDEX_PAGE_NB_HITS => array( 59 'aggregation' => 'sum', 60 'query' => "count(*)" 61 ), 62 PiwikMetrics::INDEX_PAGE_SUM_TIME_GENERATION => array( 63 'aggregation' => 'sum', 64 'query' => "sum( 65 case when " . Action::DB_COLUMN_CUSTOM_FLOAT . " is null 66 then 0 67 else " . Action::DB_COLUMN_CUSTOM_FLOAT . " 68 end 69 ) / 1000" 70 ), 71 PiwikMetrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION => array( 72 'aggregation' => 'sum', 73 'query' => "sum( 74 case when " . Action::DB_COLUMN_CUSTOM_FLOAT . " is null 75 then 0 76 else 1 77 end 78 )" 79 ), 80 PiwikMetrics::INDEX_PAGE_MIN_TIME_GENERATION => array( 81 'aggregation' => 'min', 82 'query' => "min(" . Action::DB_COLUMN_CUSTOM_FLOAT . ") / 1000" 83 ), 84 PiwikMetrics::INDEX_PAGE_MAX_TIME_GENERATION => array( 85 'aggregation' => 'max', 86 'query' => "max(" . Action::DB_COLUMN_CUSTOM_FLOAT . ") / 1000" 87 ), 88 ); 89 90 Piwik::postEvent('Actions.Archiving.addActionMetrics', array(&$metricsConfig)); 91 92 return $metricsConfig; 93 } 94} 95