PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.14.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.14.1
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Metrics.php
matomo / app / core Last commit date
API 3 years ago Access 3 years ago Application 4 years ago Archive 3 years ago ArchiveProcessor 3 years ago Archiver 5 years ago AssetManager 3 years ago Auth 3 years ago Category 5 years ago Changes 3 years ago CliMulti 4 years ago Columns 3 years ago Concurrency 3 years ago Config 4 years ago Container 4 years ago CronArchive 3 years ago DataAccess 3 years ago DataFiles 5 years ago DataTable 3 years ago Db 3 years ago DeviceDetector 3 years ago Email 5 years ago Exception 3 years ago Http 4 years ago Intl 4 years ago Mail 3 years ago Measurable 5 years ago Menu 3 years ago Metrics 4 years ago Notification 4 years ago Period 4 years ago Plugin 3 years ago ProfessionalServices 4 years ago Report 5 years ago ReportRenderer 3 years ago Scheduler 4 years ago Segment 3 years ago Session 4 years ago Settings 3 years ago Tracker 3 years ago Translation 4 years ago UpdateCheck 5 years ago Updater 3 years ago Updates 3 years ago Validators 4 years ago View 4 years ago ViewDataTable 3 years ago Visualization 4 years ago Widget 5 years ago .htaccess 6 years ago Access.php 4 years ago Archive.php 4 years ago ArchiveProcessor.php 3 years ago AssetManager.php 4 years ago Auth.php 5 years ago AuthResult.php 5 years ago BaseFactory.php 5 years ago Cache.php 5 years ago CacheId.php 5 years ago CliMulti.php 4 years ago Common.php 3 years ago Config.php 3 years ago Console.php 3 years ago Context.php 5 years ago Cookie.php 3 years ago CronArchive.php 3 years ago DataArray.php 4 years ago DataTable.php 3 years ago Date.php 3 years ago Db.php 4 years ago DbHelper.php 3 years ago Development.php 5 years ago ErrorHandler.php 5 years ago EventDispatcher.php 3 years ago ExceptionHandler.php 3 years ago FileIntegrity.php 3 years ago Filechecks.php 4 years ago Filesystem.php 3 years ago FrontController.php 3 years ago Http.php 3 years ago IP.php 4 years ago Log.php 4 years ago LogDeleter.php 4 years ago Mail.php 3 years ago Metrics.php 3 years ago NoAccessException.php 5 years ago Nonce.php 3 years ago Notification.php 5 years ago NumberFormatter.php 4 years ago Option.php 4 years ago Period.php 5 years ago Piwik.php 3 years ago Plugin.php 4 years ago Profiler.php 4 years ago ProxyHeaders.php 5 years ago ProxyHttp.php 3 years ago QuickForm2.php 5 years ago RankingQuery.php 3 years ago ReportRenderer.php 4 years ago Segment.php 3 years ago Sequence.php 5 years ago Session.php 3 years ago SettingsPiwik.php 3 years ago SettingsServer.php 5 years ago Singleton.php 5 years ago Site.php 3 years ago SiteContentDetector.php 3 years ago SupportedBrowser.php 3 years ago TCPDF.php 5 years ago Theme.php 5 years ago Timer.php 5 years ago Tracker.php 4 years ago Twig.php 4 years ago Unzip.php 5 years ago UpdateCheck.php 5 years ago Updater.php 4 years ago UpdaterErrorException.php 5 years ago Updates.php 5 years ago Url.php 3 years ago UrlHelper.php 3 years ago Version.php 3 years ago View.php 3 years ago bootstrap.php 3 years ago dispatch.php 5 years ago testMinimumPhpVersion.php 3 years ago
Metrics.php
585 lines
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 */
9 namespace Piwik;
10
11 use Piwik\Cache as PiwikCache;
12 use Piwik\Columns\Dimension;
13
14 require_once PIWIK_INCLUDE_PATH . "/core/Piwik.php";
15
16 /**
17 * This class contains metadata regarding core metrics and contains several
18 * related helper functions.
19 *
20 * Of note are the `INDEX_...` constants. In the database, metric column names
21 * in {@link DataTable} rows are stored as integers to save space. The integer
22 * values used are determined by these constants.
23 *
24 * @api
25 */
26 class Metrics
27 {
28 /*
29 * When saving DataTables in the DB, we replace all columns name with these IDs. This saves many bytes,
30 * eg. INDEX_NB_UNIQ_VISITORS is an integer: 4 bytes, but 'nb_uniq_visitors' is 16 bytes at least
31 */
32 const INDEX_NB_UNIQ_VISITORS = 1;
33 const INDEX_NB_VISITS = 2;
34 const INDEX_NB_ACTIONS = 3;
35 const INDEX_MAX_ACTIONS = 4;
36 const INDEX_SUM_VISIT_LENGTH = 5;
37 const INDEX_BOUNCE_COUNT = 6;
38 const INDEX_NB_VISITS_CONVERTED = 7;
39 const INDEX_NB_CONVERSIONS = 8;
40 const INDEX_REVENUE = 9;
41 const INDEX_GOALS = 10;
42 const INDEX_SUM_DAILY_NB_UNIQ_VISITORS = 11;
43
44 // Specific to the Actions reports
45 const INDEX_PAGE_NB_HITS = 12;
46 const INDEX_PAGE_SUM_TIME_SPENT = 13;
47 const INDEX_PAGE_EXIT_NB_UNIQ_VISITORS = 14;
48 const INDEX_PAGE_EXIT_NB_VISITS = 15;
49 const INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS = 16;
50 const INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS = 17;
51 const INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS = 18;
52 const INDEX_PAGE_ENTRY_NB_VISITS = 19;
53 const INDEX_PAGE_ENTRY_NB_ACTIONS = 20;
54 const INDEX_PAGE_ENTRY_SUM_VISIT_LENGTH = 21;
55 const INDEX_PAGE_ENTRY_BOUNCE_COUNT = 22;
56
57 // Ecommerce Items reports
58 const INDEX_ECOMMERCE_ITEM_REVENUE = 23;
59 const INDEX_ECOMMERCE_ITEM_QUANTITY = 24;
60 const INDEX_ECOMMERCE_ITEM_PRICE = 25;
61 const INDEX_ECOMMERCE_ORDERS = 26;
62 const INDEX_ECOMMERCE_ITEM_PRICE_VIEWED = 27;
63
64 // Site Search
65 const INDEX_SITE_SEARCH_HAS_NO_RESULT = 28;
66 const INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS = 29;
67
68 // Performance Analytics
69 const INDEX_PAGE_SUM_TIME_GENERATION = 30;
70 const INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION = 31;
71 const INDEX_PAGE_MIN_TIME_GENERATION = 32;
72 const INDEX_PAGE_MAX_TIME_GENERATION = 33;
73
74 // Events
75 const INDEX_EVENT_NB_HITS = 34;
76 const INDEX_EVENT_SUM_EVENT_VALUE = 35;
77 const INDEX_EVENT_MIN_EVENT_VALUE = 36;
78 const INDEX_EVENT_MAX_EVENT_VALUE = 37;
79 const INDEX_EVENT_NB_HITS_WITH_VALUE = 38;
80
81 // Number of unique User IDs
82 const INDEX_NB_USERS = 39;
83 const INDEX_SUM_DAILY_NB_USERS = 40;
84
85 // Contents
86 const INDEX_CONTENT_NB_IMPRESSIONS = 41;
87 const INDEX_CONTENT_NB_INTERACTIONS = 42;
88
89 // Unique visitors fingerprints (useful to process unique visitors across websites)
90 const INDEX_NB_UNIQ_FINGERPRINTS = 43;
91
92 // Goal reports
93 const INDEX_GOAL_NB_CONVERSIONS = 1;
94 const INDEX_GOAL_REVENUE = 2;
95 const INDEX_GOAL_NB_VISITS_CONVERTED = 3;
96 const INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL = 4;
97 const INDEX_GOAL_ECOMMERCE_REVENUE_TAX = 5;
98 const INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING = 6;
99 const INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT = 7;
100 const INDEX_GOAL_ECOMMERCE_ITEMS = 8;
101 const INDEX_GOAL_NB_PAGES_UNIQ_BEFORE = 9;
102 const INDEX_GOAL_NB_CONVERSIONS_ATTRIB = 10;
103 const INDEX_GOAL_NB_CONVERSIONS_PAGE_RATE = 11;
104 const INDEX_GOAL_NB_CONVERSIONS_PAGE_UNIQ = 12;
105 const INDEX_GOAL_NB_CONVERSIONS_ENTRY_RATE = 13;
106 const INDEX_GOAL_REVENUE_PER_ENTRY = 14;
107 const INDEX_GOAL_REVENUE_ATTRIB = 15;
108 const INDEX_GOAL_NB_CONVERSIONS_ENTRY = 16;
109 const INDEX_GOAL_REVENUE_ENTRY = 17;
110
111 public static $mappingFromIdToName = array(
112 Metrics::INDEX_NB_UNIQ_VISITORS => 'nb_uniq_visitors',
113 Metrics::INDEX_NB_UNIQ_FINGERPRINTS => 'nb_uniq_fingerprints',
114 Metrics::INDEX_NB_VISITS => 'nb_visits',
115 Metrics::INDEX_NB_ACTIONS => 'nb_actions',
116 Metrics::INDEX_NB_USERS => 'nb_users',
117 Metrics::INDEX_MAX_ACTIONS => 'max_actions',
118 Metrics::INDEX_SUM_VISIT_LENGTH => 'sum_visit_length',
119 Metrics::INDEX_BOUNCE_COUNT => 'bounce_count',
120 Metrics::INDEX_NB_VISITS_CONVERTED => 'nb_visits_converted',
121 Metrics::INDEX_NB_CONVERSIONS => 'nb_conversions',
122 Metrics::INDEX_REVENUE => 'revenue',
123 Metrics::INDEX_GOALS => 'goals',
124 Metrics::INDEX_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_nb_uniq_visitors',
125 Metrics::INDEX_SUM_DAILY_NB_USERS => 'sum_daily_nb_users',
126
127 // Actions metrics
128 Metrics::INDEX_PAGE_NB_HITS => 'nb_hits',
129 Metrics::INDEX_PAGE_SUM_TIME_SPENT => 'sum_time_spent',
130 Metrics::INDEX_PAGE_SUM_TIME_GENERATION => 'sum_time_generation',
131 Metrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION => 'nb_hits_with_time_generation',
132 Metrics::INDEX_PAGE_MIN_TIME_GENERATION => 'min_time_generation',
133 Metrics::INDEX_PAGE_MAX_TIME_GENERATION => 'max_time_generation',
134
135 Metrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS => 'exit_nb_uniq_visitors',
136 Metrics::INDEX_PAGE_EXIT_NB_VISITS => 'exit_nb_visits',
137 Metrics::INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_exit_nb_uniq_visitors',
138
139 Metrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS => 'entry_nb_uniq_visitors',
140 Metrics::INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_entry_nb_uniq_visitors',
141 Metrics::INDEX_PAGE_ENTRY_NB_VISITS => 'entry_nb_visits',
142 Metrics::INDEX_PAGE_ENTRY_NB_ACTIONS => 'entry_nb_actions',
143 Metrics::INDEX_PAGE_ENTRY_SUM_VISIT_LENGTH => 'entry_sum_visit_length',
144 Metrics::INDEX_PAGE_ENTRY_BOUNCE_COUNT => 'entry_bounce_count',
145 Metrics::INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS => 'nb_hits_following_search',
146
147 // Items reports metrics
148 Metrics::INDEX_ECOMMERCE_ITEM_REVENUE => 'revenue',
149 Metrics::INDEX_ECOMMERCE_ITEM_QUANTITY => 'quantity',
150 Metrics::INDEX_ECOMMERCE_ITEM_PRICE => 'price',
151 Metrics::INDEX_ECOMMERCE_ITEM_PRICE_VIEWED => 'price_viewed',
152 Metrics::INDEX_ECOMMERCE_ORDERS => 'orders',
153
154 // Events
155 Metrics::INDEX_EVENT_NB_HITS => 'nb_events',
156 Metrics::INDEX_EVENT_SUM_EVENT_VALUE => 'sum_event_value',
157 Metrics::INDEX_EVENT_MIN_EVENT_VALUE => 'min_event_value',
158 Metrics::INDEX_EVENT_MAX_EVENT_VALUE => 'max_event_value',
159 Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE => 'nb_events_with_value',
160
161 // Contents
162 Metrics::INDEX_CONTENT_NB_IMPRESSIONS => 'nb_impressions',
163 Metrics::INDEX_CONTENT_NB_INTERACTIONS => 'nb_interactions'
164 );
165
166 public static $mappingFromIdToNameGoal = array(
167 Metrics::INDEX_GOAL_NB_CONVERSIONS => 'nb_conversions',
168 Metrics::INDEX_GOAL_NB_VISITS_CONVERTED => 'nb_visits_converted',
169 Metrics::INDEX_GOAL_REVENUE => 'revenue',
170 Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL => 'revenue_subtotal',
171 Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX => 'revenue_tax',
172 Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING => 'revenue_shipping',
173 Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT => 'revenue_discount',
174 Metrics::INDEX_GOAL_ECOMMERCE_ITEMS => 'items',
175 Metrics::INDEX_GOAL_NB_PAGES_UNIQ_BEFORE => 'nb_conv_pages_before',
176 Metrics::INDEX_GOAL_NB_CONVERSIONS_ATTRIB => 'nb_conversions_attrib',
177 Metrics::INDEX_GOAL_NB_CONVERSIONS_PAGE_RATE => 'nb_conversions_page_rate',
178 Metrics::INDEX_GOAL_NB_CONVERSIONS_PAGE_UNIQ => 'nb_conversions_page_uniq',
179 Metrics::INDEX_GOAL_NB_CONVERSIONS_ENTRY_RATE => 'nb_conversions_entry_rate',
180 Metrics::INDEX_GOAL_REVENUE_PER_ENTRY => 'revenue_per_entry',
181 Metrics::INDEX_GOAL_REVENUE_ATTRIB => 'revenue_attrib',
182 Metrics::INDEX_GOAL_NB_CONVERSIONS_ENTRY => 'nb_conversions_entry',
183 Metrics::INDEX_GOAL_REVENUE_ENTRY => 'revenue_entry',
184 );
185
186 protected static $metricsAggregatedFromLogs = array(
187 Metrics::INDEX_NB_UNIQ_VISITORS,
188 Metrics::INDEX_NB_VISITS,
189 Metrics::INDEX_NB_ACTIONS,
190 Metrics::INDEX_NB_USERS,
191 Metrics::INDEX_MAX_ACTIONS,
192 Metrics::INDEX_SUM_VISIT_LENGTH,
193 Metrics::INDEX_BOUNCE_COUNT,
194 Metrics::INDEX_NB_VISITS_CONVERTED,
195 );
196
197 public static function getMappingFromIdToName()
198 {
199 $cache = PiwikCache::getTransientCache();
200 $cacheKey = CacheId::siteAware(CacheId::pluginAware('Metrics.mappingFromIdToName'));
201
202 $value = $cache->fetch($cacheKey);
203 if (empty($value)) {
204 $value = self::$mappingFromIdToName;
205
206 /**
207 * Use this event if your plugin uses custom metric integer IDs to associate those IDs with the
208 * actual metric names (eg, 2 => nb_visits). This allows matomo to automate the replacing
209 * of IDs => metric names for your new metrics.
210 *
211 * **Example**
212 *
213 * public function addMetricIdToNameMapping(&$mapping)
214 * {
215 * $mapping[Archiver::INDEX_MY_NEW_METRIC] = $mapping['MyPlugin_myNewMetric'];
216 * }
217 *
218 * @ignore
219 */
220 Piwik::postEvent('Metrics.addMetricIdToNameMapping', [&$value]);
221
222 $cache->save($cacheKey, $value);
223 }
224 return $value;
225 }
226
227 public static function getVisitsMetricNames()
228 {
229 $names = array();
230
231 foreach (self::$metricsAggregatedFromLogs as $metricId) {
232 $names[$metricId] = self::$mappingFromIdToName[$metricId];
233 }
234
235 return $names;
236 }
237
238 public static function getMappingFromNameToId()
239 {
240 static $nameToId = null;
241 if ($nameToId === null) {
242 $nameToId = array_flip(self::$mappingFromIdToName);
243 }
244 return $nameToId;
245 }
246
247 public static function getMappingFromNameToIdGoal()
248 {
249 static $nameToId = null;
250 if ($nameToId === null) {
251 $nameToId = array_flip(self::$mappingFromIdToNameGoal);
252 }
253 return $nameToId;
254 }
255
256 /**
257 * Is a lower value for a given column better?
258 * @param $column
259 * @return bool
260 *
261 * @ignore
262 */
263 public static function isLowerValueBetter($column)
264 {
265 $isLowerBetter = null;
266
267 /**
268 * Use this event to define if a lower value of a metric is better.
269 *
270 * @param string $isLowerBetter should be set to a boolean indicating if lower is better
271 * @param string $column name of the column to determine
272 *
273 * **Example**
274 *
275 * public function checkIsLowerMetricValueBetter(&$isLowerBetter, $metric)
276 * {
277 * if ($metric === 'position') {
278 * $isLowerBetter = true;
279 * }
280 * }
281 */
282 Piwik::postEvent('Metrics.isLowerValueBetter', [&$isLowerBetter, $column]);
283
284 if (!is_null($isLowerBetter)) {
285 return true;
286 }
287
288 $lowerIsBetterPatterns = array(
289 'bounce', 'exit'
290 );
291
292 foreach ($lowerIsBetterPatterns as $pattern) {
293 if (strpos($column, $pattern) !== false) {
294 return true;
295 }
296 }
297
298 return false;
299 }
300
301 /**
302 * Derive the unit name from a column name
303 * @param $column
304 * @param $idSite
305 * @return string
306 * @ignore
307 */
308 public static function getUnit($column, $idSite)
309 {
310 $nameToUnit = array(
311 '_rate' => '%',
312 'revenue' => Site::getCurrencySymbolFor($idSite),
313 '_time_' => 's'
314 );
315
316 $unit = null;
317
318 /**
319 * Use this event to define units for custom metrics used in evolution graphs and row evolution only.
320 *
321 * @param string $unit should hold the unit (e.g. %, €, s or empty string)
322 * @param string $column name of the column to determine
323 * @param string $idSite id of the current site
324 */
325 Piwik::postEvent('Metrics.getEvolutionUnit', [&$unit, $column, $idSite]);
326
327 if (!empty($unit)) {
328 return $unit;
329 }
330
331 foreach ($nameToUnit as $pattern => $type) {
332 if (strpos($column, $pattern) !== false) {
333 return $type;
334 }
335 }
336
337 return '';
338 }
339
340 public static function getDefaultMetricSemanticTypes(): array
341 {
342 $cacheId = CacheId::pluginAware('DefaultMetricSemanticTypes');
343 $cache = PiwikCache::getTransientCache();
344
345 $types = $cache->fetch($cacheId);
346 if (empty($types)) {
347 $types = [
348 'nb_visits' => Dimension::TYPE_NUMBER,
349 'nb_uniq_visitors' => Dimension::TYPE_NUMBER,
350 'nb_actions' => Dimension::TYPE_NUMBER,
351 'nb_users' => Dimension::TYPE_NUMBER,
352 'avg_time_on_page' => Dimension::TYPE_DURATION_S,
353 'sum_time_spent' => Dimension::TYPE_DURATION_S,
354 'sum_visit_length' => Dimension::TYPE_DURATION_S,
355 'bounce_count' => Dimension::TYPE_NUMBER,
356 'bounce_count_returning' => Dimension::TYPE_NUMBER,
357 'max_actions' => Dimension::TYPE_NUMBER,
358 'max_actions_returning' => Dimension::TYPE_NUMBER,
359 'nb_visits_converted_returning' => Dimension::TYPE_NUMBER,
360 'sum_visit_length_returning' => Dimension::TYPE_NUMBER,
361 'nb_visits_converted' => Dimension::TYPE_NUMBER,
362 'nb_conversions' => Dimension::TYPE_NUMBER,
363 'revenue' => Dimension::TYPE_MONEY,
364 'nb_hits' => Dimension::TYPE_NUMBER,
365 'entry_nb_visits' => Dimension::TYPE_NUMBER,
366 'entry_nb_uniq_visitors' => Dimension::TYPE_NUMBER,
367 'exit_nb_visits' => Dimension::TYPE_NUMBER,
368 'exit_nb_uniq_visitors' => Dimension::TYPE_NUMBER,
369 'entry_bounce_count' => Dimension::TYPE_NUMBER,
370 'exit_bounce_count' => Dimension::TYPE_NUMBER,
371 'exit_rate' => Dimension::TYPE_PERCENT,
372 'sum_daily_nb_uniq_visitors' => Dimension::TYPE_NUMBER,
373 'sum_daily_nb_users' => Dimension::TYPE_NUMBER,
374 'sum_daily_entry_nb_uniq_visitors' => Dimension::TYPE_NUMBER,
375 'sum_daily_exit_nb_uniq_visitors' => Dimension::TYPE_NUMBER,
376 'entry_nb_actions' => Dimension::TYPE_NUMBER,
377 'entry_sum_visit_length' => Dimension::TYPE_NUMBER,
378 'nb_actions_per_visit' => Dimension::TYPE_NUMBER,
379 'avg_time_on_site' => Dimension::TYPE_DURATION_S,
380 'bounce_rate' => Dimension::TYPE_PERCENT,
381 'conversion_rate' => Dimension::TYPE_PERCENT,
382 ];
383
384 /**
385 * Use this event to notify Matomo of the semantic types of metrics your plugin adds.
386 *
387 * A metric's semantic type is metadata used primarily in integrations with Matomo
388 * and third party services/applications. It provides information that can be used
389 * to determine how to display or use the information.
390 *
391 * It is recommended for your plugin to provide this information so users of third
392 * party services that connect with Matomo can make full use of the data your plugin
393 * tracks.
394 *
395 * See {@link Metrics} for the list of available semantic types.
396 *
397 * @param string $types The array mapping of metric_name => metric semantic type
398 */
399 Piwik::postEvent('Metrics.getDefaultMetricSemanticTypes', [&$types]);
400
401 $cache->save($cacheId, $types);
402 }
403
404 return $types;
405 }
406
407 public static function getDefaultMetricTranslations()
408 {
409 $cacheId = CacheId::pluginAware('DefaultMetricTranslations');
410 $cache = PiwikCache::getTransientCache();
411
412 if ($cache->contains($cacheId)) {
413 return $cache->fetch($cacheId);
414 }
415
416 $translations = array(
417 'label' => 'General_ColumnLabel',
418 'date' => 'General_Date',
419 'avg_time_on_page' => 'General_ColumnAverageTimeOnPage',
420 'sum_time_spent' => 'General_ColumnSumVisitLength',
421 'sum_visit_length' => 'General_ColumnSumVisitLength',
422 'bounce_count' => 'General_ColumnBounces',
423 'bounce_count_returning' => 'VisitFrequency_ColumnBounceCountForReturningVisits',
424 'max_actions' => 'General_ColumnMaxActions',
425 'max_actions_returning' => 'VisitFrequency_ColumnMaxActionsInReturningVisit',
426 'nb_visits_converted_returning' => 'VisitFrequency_ColumnNbReturningVisitsConverted',
427 'sum_visit_length_returning' => 'VisitFrequency_ColumnSumVisitLengthReturning',
428 'nb_visits_converted' => 'General_ColumnVisitsWithConversions',
429 'nb_conversions' => 'Goals_ColumnConversions',
430 'revenue' => 'General_ColumnRevenue',
431 'nb_hits' => 'General_ColumnPageviews',
432 'entry_nb_visits' => 'General_ColumnEntrances',
433 'entry_nb_uniq_visitors' => 'General_ColumnUniqueEntrances',
434 'exit_nb_visits' => 'General_ColumnExits',
435 'exit_nb_uniq_visitors' => 'General_ColumnUniqueExits',
436 'entry_bounce_count' => 'General_ColumnBounces',
437 'exit_bounce_count' => 'General_ColumnBounces',
438 'exit_rate' => 'General_ColumnExitRate',
439 );
440
441 $dailySum = ' (' . Piwik::translate('General_DailySum') . ')';
442 $afterEntry = ' ' . Piwik::translate('General_AfterEntry');
443
444 $translations['sum_daily_nb_uniq_visitors'] = Piwik::translate('General_ColumnNbUniqVisitors') . $dailySum;
445 $translations['sum_daily_nb_users'] = Piwik::translate('General_ColumnNbUsers') . $dailySum;
446 $translations['sum_daily_entry_nb_uniq_visitors'] = Piwik::translate('General_ColumnUniqueEntrances') . $dailySum;
447 $translations['sum_daily_exit_nb_uniq_visitors'] = Piwik::translate('General_ColumnUniqueExits') . $dailySum;
448 $translations['entry_nb_actions'] = Piwik::translate('General_ColumnNbActions') . $afterEntry;
449 $translations['entry_sum_visit_length'] = Piwik::translate('General_ColumnSumVisitLength') . $afterEntry;
450
451 $translations = array_merge(self::getDefaultMetrics(), self::getDefaultProcessedMetrics(), $translations);
452
453 /**
454 * Use this event to register translations for metrics processed by your plugin.
455 *
456 * @param string $translations The array mapping of column_name => Plugin_TranslationForColumn
457 */
458 Piwik::postEvent('Metrics.getDefaultMetricTranslations', array(&$translations));
459
460 $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations);
461
462 $cache->save($cacheId, $translations);
463
464 return $translations;
465 }
466
467 public static function getDefaultMetrics()
468 {
469 $cacheId = CacheId::languageAware('DefaultMetrics');
470 $cache = PiwikCache::getTransientCache();
471
472 if ($cache->contains($cacheId)) {
473 return $cache->fetch($cacheId);
474 }
475
476 $translations = array(
477 'nb_visits' => 'General_ColumnNbVisits',
478 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitors',
479 'nb_actions' => 'General_ColumnNbActions',
480 'nb_users' => 'General_ColumnNbUsers',
481 );
482 $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations);
483
484 $cache->save($cacheId, $translations);
485
486 return $translations;
487 }
488
489 public static function getDefaultProcessedMetrics()
490 {
491 $cacheId = CacheId::languageAware('DefaultProcessedMetrics');
492 $cache = PiwikCache::getTransientCache();
493
494 if ($cache->contains($cacheId)) {
495 return $cache->fetch($cacheId);
496 }
497
498 $translations = array(
499 // Processed in AddColumnsProcessedMetrics
500 'nb_actions_per_visit' => 'General_ColumnActionsPerVisit',
501 'avg_time_on_site' => 'General_ColumnAvgTimeOnSite',
502 'bounce_rate' => 'General_ColumnBounceRate',
503 'conversion_rate' => 'General_ColumnConversionRate',
504 );
505 $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations);
506
507 $cache->save($cacheId, $translations);
508
509 return $translations;
510 }
511
512 public static function getReadableColumnName($columnIdRaw)
513 {
514 $mappingIdToName = self::$mappingFromIdToName;
515
516 if (array_key_exists($columnIdRaw, $mappingIdToName)) {
517 return $mappingIdToName[$columnIdRaw];
518 }
519
520 return $columnIdRaw;
521 }
522
523 public static function getMetricIdsToProcessReportTotal()
524 {
525 return array(
526 self::INDEX_NB_VISITS,
527 self::INDEX_NB_UNIQ_VISITORS,
528 self::INDEX_NB_ACTIONS,
529 self::INDEX_PAGE_NB_HITS,
530 self::INDEX_NB_VISITS_CONVERTED,
531 self::INDEX_NB_CONVERSIONS,
532 self::INDEX_BOUNCE_COUNT,
533 self::INDEX_PAGE_ENTRY_BOUNCE_COUNT,
534 self::INDEX_PAGE_ENTRY_NB_VISITS,
535 self::INDEX_PAGE_ENTRY_NB_ACTIONS,
536 self::INDEX_PAGE_EXIT_NB_VISITS,
537 self::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS,
538 self::INDEX_REVENUE
539 );
540 }
541
542 public static function getDefaultMetricsDocumentation()
543 {
544 $cacheId = CacheId::pluginAware('DefaultMetricsDocumentation');
545 $cache = PiwikCache::getTransientCache();
546
547 if ($cache->contains($cacheId)) {
548 return $cache->fetch($cacheId);
549 }
550
551 $translations = array(
552 'nb_visits' => 'General_ColumnNbVisitsDocumentation',
553 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitorsDocumentation',
554 'nb_actions' => 'General_ColumnNbActionsDocumentation',
555 'nb_users' => 'General_ColumnNbUsersDocumentation',
556 'nb_actions_per_visit' => 'General_ColumnActionsPerVisitDocumentation',
557 'avg_time_on_site' => 'General_ColumnAvgTimeOnSiteDocumentation',
558 'bounce_rate' => 'General_ColumnBounceRateDocumentation',
559 'conversion_rate' => 'General_ColumnConversionRateDocumentation',
560 'avg_time_on_page' => 'General_ColumnAverageTimeOnPageDocumentation',
561 'nb_hits' => 'General_ColumnPageviewsDocumentation',
562 'exit_rate' => 'General_ColumnExitRateDocumentation'
563 );
564
565 /**
566 * Use this event to register translations for metrics documentation processed by your plugin.
567 *
568 * @param string[] $translations The array mapping of column_name => Plugin_TranslationForColumnDocumentation
569 */
570 Piwik::postEvent('Metrics.getDefaultMetricDocumentationTranslations', array(&$translations));
571
572 $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations);
573
574 $cache->save($cacheId, $translations);
575
576 return $translations;
577 }
578
579 public static function getPercentVisitColumn()
580 {
581 $percentVisitsLabel = str_replace(' ', '&nbsp;', Piwik::translate('General_ColumnPercentageVisits'));
582 return $percentVisitsLabel;
583 }
584 }
585