File size: 5,893 Bytes
2a0a63a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Actions\Reports;
use Piwik\Common;
use Piwik\Config\GeneralConfig;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\Actions\Actions;
use Piwik\Plugins\Actions\Columns\EntryPageTitle;
use Piwik\Plugins\Actions\Columns\EntryPageUrl;
use Piwik\Plugins\Actions\Columns\ExitPageTitle;
use Piwik\Plugins\Actions\Columns\ExitPageUrl;
use Piwik\Plugins\Actions\Columns\PageTitle;
use Piwik\Plugins\Actions\Columns\PageUrl;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
use Piwik\API\Request;
abstract class Base extends \Piwik\Plugin\Report
{
protected function init()
{
$this->categoryId = 'General_Actions';
$this->processedMetrics = [];
$this->recursiveLabelSeparator = '/';
}
protected function addBaseDisplayProperties(ViewDataTable $view)
{
$view->config->datatable_js_type = 'ActionsDataTable';
$view->config->search_recursive = true;
$view->config->show_table_all_columns = false;
$view->requestConfig->filter_limit = Actions::ACTIONS_REPORT_ROWS_DISPLAY;
$view->config->show_all_views_icons = false;
if ($view->requestConfig->getRequestParam('performance') === '1') {
$view->requestConfig->filter_limit = 25;
// hide visualization selector
$view->config->footer_icons = [[
'class' => 'tableAllColumnsSwitch',
'buttons' => [],
]];
}
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->show_embedded_subtable = true;
}
if (Request::shouldLoadExpanded()) {
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->show_expanded = true;
}
$view->config->filters[] = function ($dataTable) {
Actions::setDataTableRowLevels($dataTable);
};
}
$view->config->filters[] = function ($dataTable) use ($view) {
if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->datatable_css_class = 'dataTableActions';
}
};
}
protected function addPageDisplayProperties(ViewDataTable $view)
{
$view->config->addTranslations(array(
'nb_hits' => Piwik::translate('General_ColumnPageviews'),
'nb_visits' => Piwik::translate('General_ColumnUniquePageviews'),
));
$formatter = new Formatter();
// add avg_generation_time tooltip
$tooltipCallback = function ($hits, $min, $max) use ($formatter) {
if (!$hits) {
return false;
}
return Piwik::translate("Actions_AvgGenerationTimeTooltip", array(
$hits,
"<br />",
$formatter->getPrettyTimeFromSeconds($min, true),
$formatter->getPrettyTimeFromSeconds($max, true),
));
};
$view->config->filters[] = array('ColumnCallbackAddMetadata',
array(
array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'),
'avg_time_generation_tooltip',
$tooltipCallback,
),
);
$this->addExcludeLowPopDisplayProperties($view);
// hide the performance columns viz in page reports when not displayed as widget
if ($view->requestConfig->getRequestParam('widget') != '1') {
$view->config->show_table_performance = false;
}
}
protected function addExcludeLowPopDisplayProperties(ViewDataTable $view)
{
if (Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') != '0') {
if (Common::getRequestVar('flat', 0, 'int') === 1) {
$view->requestConfig->filter_excludelowpop = 'nb_hits';
} else {
$view->requestConfig->filter_excludelowpop = Metrics::INDEX_PAGE_NB_HITS;
}
$view->requestConfig->filter_excludelowpop_value = function () {
// computing minimum value to exclude (2 percent of the total number of actions)
$visitsInfo = \Piwik\Plugins\VisitsSummary\Controller::getVisitsSummary()->getFirstRow();
$nbActions = $visitsInfo->getColumn('nb_actions');
$nbActionsLowPopulationThreshold = floor(0.02 * $nbActions);
// we remove 1 to make sure some actions/downloads are displayed in the case we have a very few of them
// and each of them has 1 or 2 hits...
return min($visitsInfo->getColumn('max_actions') - 1, $nbActionsLowPopulationThreshold - 1);
};
}
}
public function getRecursiveLabelSeparator()
{
$legacyDelimiter = GeneralConfig::getConfigValue('action_category_delimiter');
if (!empty($legacyDelimiter)) {
return $legacyDelimiter;
}
if (
$this->dimension instanceof PageTitle
|| $this->dimension instanceof EntryPageTitle
|| $this->dimension instanceof ExitPageTitle
) {
return GeneralConfig::getConfigValue('action_title_category_delimiter') ?: $this->recursiveLabelSeparator;
}
if (
$this->dimension instanceof PageUrl
|| $this->dimension instanceof EntryPageUrl
|| $this->dimension instanceof ExitPageUrl
) {
return GeneralConfig::getConfigValue('action_url_category_delimiter') ?: $this->recursiveLabelSeparator;
}
return parent::getRecursiveLabelSeparator();
}
}
|