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
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\PagePerformance;
use Piwik\DataTable;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
/**
*/
class PagePerformance extends \Piwik\Plugin
{
public static $availableForMethods = [
'getPageUrls',
'getEntryPageUrls',
'getExitPageUrls',
'getPageUrlsFollowingSiteSearch',
'getPageTitles',
'getEntryPageTitles',
'getExitPageTitles',
'getPageTitlesFollowingSiteSearch',
];
public function isTrackerPlugin()
{
return true;
}
/**
* @see \Piwik\Plugin::registerEvents
*/
public function registerEvents()
{
return [
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'Actions.Archiving.addActionMetrics' => 'addActionMetrics',
'ScheduledReports.processReports' => 'processReports',
'ViewDataTable.configure' => 'configureViewDataTable',
'Metrics.getDefaultMetricTranslations' => 'addMetricTranslations',
'Metrics.isLowerValueBetter' => 'isLowerValueBetter',
'API.Request.dispatch.end' => 'enrichApi'
];
}
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = 'plugins/PagePerformance/javascripts/PagePerformance.js';
$jsFiles[] = 'plugins/PagePerformance/javascripts/rowaction.js';
$jsFiles[] = 'plugins/PagePerformance/javascripts/jqplotStackedBarEvolutionGraph.js';
}
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = 'PagePerformance_RowActionTitle';
$translationKeys[] = 'PagePerformance_RowActionDescription';
$translationKeys[] = 'PagePerformance_PagePerformanceTitle';
$translationKeys[] = 'General_Total';
}
public function addMetricTranslations(&$translations)
{
$metrics = Metrics::getMetricTranslations();
$translations = array_merge($translations, $metrics);
}
public function isLowerValueBetter(&$isLowerBetter, $metric)
{
if (array_key_exists($metric, Metrics::getAllPagePerformanceMetrics())) {
$isLowerBetter = true;
}
}
public function enrichApi($dataTable, $params)
{
if ('Actions' !== $params['module'] || !$dataTable instanceof DataTable\DataTableInterface) {
return;
}
// remove additional metrics for action reports that don't have data
if (!in_array($params['action'], self::$availableForMethods)) {
$dataTable->deleteColumns([
'sum_time_network',
'nb_hits_with_time_network',
'min_time_network',
'max_time_network',
'sum_time_server',
'nb_hits_with_time_server',
'min_time_server',
'max_time_server',
'sum_time_transfer',
'nb_hits_with_time_transfer',
'min_time_transfer',
'max_time_transfer',
'sum_time_dom_processing',
'nb_hits_with_time_dom_processing',
'min_time_dom_processing',
'max_time_dom_processing',
'sum_time_dom_completion',
'nb_hits_with_time_dom_completion',
'min_time_dom_completion',
'max_time_dom_completion',
'sum_time_on_load',
'nb_hits_with_time_on_load',
'min_time_on_load',
'max_time_on_load',
], true);
return;
}
$dataTable->filter(function (DataTable $dataTable) {
$extraProcessedMetrics = $dataTable->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
if (empty($extraProcessedMetrics)) {
$extraProcessedMetrics = array();
}
foreach (Metrics::getAllPagePerformanceMetrics() as $pagePerformanceMetric) {
$extraProcessedMetrics[] = $pagePerformanceMetric;
}
$dataTable->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
});
}
public function configureViewDataTable(ViewDataTable $view)
{
$module = $view->requestConfig->getApiModuleToRequest();
$method = $view->requestConfig->getApiMethodToRequest();
if ('Actions' === $module && in_array($method, self::$availableForMethods) && $view instanceof HtmlTable) {
$view->config->columns_to_display[] = 'avg_page_load_time';
}
}
public function addActionMetrics(&$metricsConfig)
{
Metrics::attachActionMetrics($metricsConfig);
}
public function processReports(&$processedReports, $reportType, $outputType, $report)
{
foreach ($processedReports as &$processedReport) {
$metadata = &$processedReport['metadata'];
// Ensure average page load time is displayed in the evolution chart
if ($metadata['module'] == 'PagePerformance') {
$metadata['imageGraphUrl'] .= '&columns=avg_page_load_time';
$metadata['imageGraphEvolutionUrl'] .= '&columns=avg_page_load_time';
}
}
}
}
|