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
4 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
4 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
4 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
5 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
4 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
517 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 | |
| 13 | require_once PIWIK_INCLUDE_PATH . "/core/Piwik.php"; |
| 14 | |
| 15 | /** |
| 16 | * This class contains metadata regarding core metrics and contains several |
| 17 | * related helper functions. |
| 18 | * |
| 19 | * Of note are the `INDEX_...` constants. In the database, metric column names |
| 20 | * in {@link DataTable} rows are stored as integers to save space. The integer |
| 21 | * values used are determined by these constants. |
| 22 | * |
| 23 | * @api |
| 24 | */ |
| 25 | class Metrics |
| 26 | { |
| 27 | /* |
| 28 | * When saving DataTables in the DB, we replace all columns name with these IDs. This saves many bytes, |
| 29 | * eg. INDEX_NB_UNIQ_VISITORS is an integer: 4 bytes, but 'nb_uniq_visitors' is 16 bytes at least |
| 30 | */ |
| 31 | const INDEX_NB_UNIQ_VISITORS = 1; |
| 32 | const INDEX_NB_VISITS = 2; |
| 33 | const INDEX_NB_ACTIONS = 3; |
| 34 | const INDEX_MAX_ACTIONS = 4; |
| 35 | const INDEX_SUM_VISIT_LENGTH = 5; |
| 36 | const INDEX_BOUNCE_COUNT = 6; |
| 37 | const INDEX_NB_VISITS_CONVERTED = 7; |
| 38 | const INDEX_NB_CONVERSIONS = 8; |
| 39 | const INDEX_REVENUE = 9; |
| 40 | const INDEX_GOALS = 10; |
| 41 | const INDEX_SUM_DAILY_NB_UNIQ_VISITORS = 11; |
| 42 | |
| 43 | // Specific to the Actions reports |
| 44 | const INDEX_PAGE_NB_HITS = 12; |
| 45 | const INDEX_PAGE_SUM_TIME_SPENT = 13; |
| 46 | const INDEX_PAGE_EXIT_NB_UNIQ_VISITORS = 14; |
| 47 | const INDEX_PAGE_EXIT_NB_VISITS = 15; |
| 48 | const INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS = 16; |
| 49 | const INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS = 17; |
| 50 | const INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS = 18; |
| 51 | const INDEX_PAGE_ENTRY_NB_VISITS = 19; |
| 52 | const INDEX_PAGE_ENTRY_NB_ACTIONS = 20; |
| 53 | const INDEX_PAGE_ENTRY_SUM_VISIT_LENGTH = 21; |
| 54 | const INDEX_PAGE_ENTRY_BOUNCE_COUNT = 22; |
| 55 | |
| 56 | // Ecommerce Items reports |
| 57 | const INDEX_ECOMMERCE_ITEM_REVENUE = 23; |
| 58 | const INDEX_ECOMMERCE_ITEM_QUANTITY = 24; |
| 59 | const INDEX_ECOMMERCE_ITEM_PRICE = 25; |
| 60 | const INDEX_ECOMMERCE_ORDERS = 26; |
| 61 | const INDEX_ECOMMERCE_ITEM_PRICE_VIEWED = 27; |
| 62 | |
| 63 | // Site Search |
| 64 | const INDEX_SITE_SEARCH_HAS_NO_RESULT = 28; |
| 65 | const INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS = 29; |
| 66 | |
| 67 | // Performance Analytics |
| 68 | const INDEX_PAGE_SUM_TIME_GENERATION = 30; |
| 69 | const INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION = 31; |
| 70 | const INDEX_PAGE_MIN_TIME_GENERATION = 32; |
| 71 | const INDEX_PAGE_MAX_TIME_GENERATION = 33; |
| 72 | |
| 73 | // Events |
| 74 | const INDEX_EVENT_NB_HITS = 34; |
| 75 | const INDEX_EVENT_SUM_EVENT_VALUE = 35; |
| 76 | const INDEX_EVENT_MIN_EVENT_VALUE = 36; |
| 77 | const INDEX_EVENT_MAX_EVENT_VALUE = 37; |
| 78 | const INDEX_EVENT_NB_HITS_WITH_VALUE = 38; |
| 79 | |
| 80 | // Number of unique User IDs |
| 81 | const INDEX_NB_USERS = 39; |
| 82 | const INDEX_SUM_DAILY_NB_USERS = 40; |
| 83 | |
| 84 | // Contents |
| 85 | const INDEX_CONTENT_NB_IMPRESSIONS = 41; |
| 86 | const INDEX_CONTENT_NB_INTERACTIONS = 42; |
| 87 | |
| 88 | // Unique visitors fingerprints (useful to process unique visitors across websites) |
| 89 | const INDEX_NB_UNIQ_FINGERPRINTS = 43; |
| 90 | |
| 91 | // Goal reports |
| 92 | const INDEX_GOAL_NB_CONVERSIONS = 1; |
| 93 | const INDEX_GOAL_REVENUE = 2; |
| 94 | const INDEX_GOAL_NB_VISITS_CONVERTED = 3; |
| 95 | const INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL = 4; |
| 96 | const INDEX_GOAL_ECOMMERCE_REVENUE_TAX = 5; |
| 97 | const INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING = 6; |
| 98 | const INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT = 7; |
| 99 | const INDEX_GOAL_ECOMMERCE_ITEMS = 8; |
| 100 | const INDEX_GOAL_NB_PAGES_UNIQ_BEFORE = 9; |
| 101 | const INDEX_GOAL_NB_CONVERSIONS_ATTRIB = 10; |
| 102 | const INDEX_GOAL_NB_CONVERSIONS_PAGE_RATE = 11; |
| 103 | const INDEX_GOAL_NB_CONVERSIONS_PAGE_UNIQ = 12; |
| 104 | const INDEX_GOAL_NB_CONVERSIONS_ENTRY_RATE = 13; |
| 105 | const INDEX_GOAL_REVENUE_PER_ENTRY = 14; |
| 106 | const INDEX_GOAL_REVENUE_ATTRIB = 15; |
| 107 | const INDEX_GOAL_NB_CONVERSIONS_ENTRY = 16; |
| 108 | const INDEX_GOAL_REVENUE_ENTRY = 17; |
| 109 | |
| 110 | public static $mappingFromIdToName = array( |
| 111 | Metrics::INDEX_NB_UNIQ_VISITORS => 'nb_uniq_visitors', |
| 112 | Metrics::INDEX_NB_UNIQ_FINGERPRINTS => 'nb_uniq_fingerprints', |
| 113 | Metrics::INDEX_NB_VISITS => 'nb_visits', |
| 114 | Metrics::INDEX_NB_ACTIONS => 'nb_actions', |
| 115 | Metrics::INDEX_NB_USERS => 'nb_users', |
| 116 | Metrics::INDEX_MAX_ACTIONS => 'max_actions', |
| 117 | Metrics::INDEX_SUM_VISIT_LENGTH => 'sum_visit_length', |
| 118 | Metrics::INDEX_BOUNCE_COUNT => 'bounce_count', |
| 119 | Metrics::INDEX_NB_VISITS_CONVERTED => 'nb_visits_converted', |
| 120 | Metrics::INDEX_NB_CONVERSIONS => 'nb_conversions', |
| 121 | Metrics::INDEX_REVENUE => 'revenue', |
| 122 | Metrics::INDEX_GOALS => 'goals', |
| 123 | Metrics::INDEX_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_nb_uniq_visitors', |
| 124 | Metrics::INDEX_SUM_DAILY_NB_USERS => 'sum_daily_nb_users', |
| 125 | |
| 126 | // Actions metrics |
| 127 | Metrics::INDEX_PAGE_NB_HITS => 'nb_hits', |
| 128 | Metrics::INDEX_PAGE_SUM_TIME_SPENT => 'sum_time_spent', |
| 129 | Metrics::INDEX_PAGE_SUM_TIME_GENERATION => 'sum_time_generation', |
| 130 | Metrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION => 'nb_hits_with_time_generation', |
| 131 | Metrics::INDEX_PAGE_MIN_TIME_GENERATION => 'min_time_generation', |
| 132 | Metrics::INDEX_PAGE_MAX_TIME_GENERATION => 'max_time_generation', |
| 133 | |
| 134 | Metrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS => 'exit_nb_uniq_visitors', |
| 135 | Metrics::INDEX_PAGE_EXIT_NB_VISITS => 'exit_nb_visits', |
| 136 | Metrics::INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_exit_nb_uniq_visitors', |
| 137 | |
| 138 | Metrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS => 'entry_nb_uniq_visitors', |
| 139 | Metrics::INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_entry_nb_uniq_visitors', |
| 140 | Metrics::INDEX_PAGE_ENTRY_NB_VISITS => 'entry_nb_visits', |
| 141 | Metrics::INDEX_PAGE_ENTRY_NB_ACTIONS => 'entry_nb_actions', |
| 142 | Metrics::INDEX_PAGE_ENTRY_SUM_VISIT_LENGTH => 'entry_sum_visit_length', |
| 143 | Metrics::INDEX_PAGE_ENTRY_BOUNCE_COUNT => 'entry_bounce_count', |
| 144 | Metrics::INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS => 'nb_hits_following_search', |
| 145 | |
| 146 | // Items reports metrics |
| 147 | Metrics::INDEX_ECOMMERCE_ITEM_REVENUE => 'revenue', |
| 148 | Metrics::INDEX_ECOMMERCE_ITEM_QUANTITY => 'quantity', |
| 149 | Metrics::INDEX_ECOMMERCE_ITEM_PRICE => 'price', |
| 150 | Metrics::INDEX_ECOMMERCE_ITEM_PRICE_VIEWED => 'price_viewed', |
| 151 | Metrics::INDEX_ECOMMERCE_ORDERS => 'orders', |
| 152 | |
| 153 | // Events |
| 154 | Metrics::INDEX_EVENT_NB_HITS => 'nb_events', |
| 155 | Metrics::INDEX_EVENT_SUM_EVENT_VALUE => 'sum_event_value', |
| 156 | Metrics::INDEX_EVENT_MIN_EVENT_VALUE => 'min_event_value', |
| 157 | Metrics::INDEX_EVENT_MAX_EVENT_VALUE => 'max_event_value', |
| 158 | Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE => 'nb_events_with_value', |
| 159 | |
| 160 | // Contents |
| 161 | Metrics::INDEX_CONTENT_NB_IMPRESSIONS => 'nb_impressions', |
| 162 | Metrics::INDEX_CONTENT_NB_INTERACTIONS => 'nb_interactions' |
| 163 | ); |
| 164 | |
| 165 | public static $mappingFromIdToNameGoal = array( |
| 166 | Metrics::INDEX_GOAL_NB_CONVERSIONS => 'nb_conversions', |
| 167 | Metrics::INDEX_GOAL_NB_VISITS_CONVERTED => 'nb_visits_converted', |
| 168 | Metrics::INDEX_GOAL_REVENUE => 'revenue', |
| 169 | Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL => 'revenue_subtotal', |
| 170 | Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX => 'revenue_tax', |
| 171 | Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING => 'revenue_shipping', |
| 172 | Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT => 'revenue_discount', |
| 173 | Metrics::INDEX_GOAL_ECOMMERCE_ITEMS => 'items', |
| 174 | Metrics::INDEX_GOAL_NB_PAGES_UNIQ_BEFORE => 'nb_conv_pages_before', |
| 175 | Metrics::INDEX_GOAL_NB_CONVERSIONS_ATTRIB => 'nb_conversions_attrib', |
| 176 | Metrics::INDEX_GOAL_NB_CONVERSIONS_PAGE_RATE => 'nb_conversions_page_rate', |
| 177 | Metrics::INDEX_GOAL_NB_CONVERSIONS_PAGE_UNIQ => 'nb_conversions_page_uniq', |
| 178 | Metrics::INDEX_GOAL_NB_CONVERSIONS_ENTRY_RATE => 'nb_conversions_entry_rate', |
| 179 | Metrics::INDEX_GOAL_REVENUE_PER_ENTRY => 'revenue_per_entry', |
| 180 | Metrics::INDEX_GOAL_REVENUE_ATTRIB => 'revenue_attrib', |
| 181 | Metrics::INDEX_GOAL_NB_CONVERSIONS_ENTRY => 'nb_conversions_entry', |
| 182 | Metrics::INDEX_GOAL_REVENUE_ENTRY => 'revenue_entry', |
| 183 | ); |
| 184 | |
| 185 | protected static $metricsAggregatedFromLogs = array( |
| 186 | Metrics::INDEX_NB_UNIQ_VISITORS, |
| 187 | Metrics::INDEX_NB_VISITS, |
| 188 | Metrics::INDEX_NB_ACTIONS, |
| 189 | Metrics::INDEX_NB_USERS, |
| 190 | Metrics::INDEX_MAX_ACTIONS, |
| 191 | Metrics::INDEX_SUM_VISIT_LENGTH, |
| 192 | Metrics::INDEX_BOUNCE_COUNT, |
| 193 | Metrics::INDEX_NB_VISITS_CONVERTED, |
| 194 | ); |
| 195 | |
| 196 | public static function getMappingFromIdToName() |
| 197 | { |
| 198 | $cache = PiwikCache::getTransientCache(); |
| 199 | $cacheKey = CacheId::siteAware(CacheId::pluginAware('Metrics.mappingFromIdToName')); |
| 200 | |
| 201 | $value = $cache->fetch($cacheKey); |
| 202 | if (empty($value)) { |
| 203 | $value = self::$mappingFromIdToName; |
| 204 | |
| 205 | /** |
| 206 | * Use this event if your plugin uses custom metric integer IDs to associate those IDs with the |
| 207 | * actual metric names (eg, 2 => nb_visits). This allows matomo to automate the replacing |
| 208 | * of IDs => metric names for your new metrics. |
| 209 | * |
| 210 | * **Example** |
| 211 | * |
| 212 | * public function addMetricIdToNameMapping(&$mapping) |
| 213 | * { |
| 214 | * $mapping[Archiver::INDEX_MY_NEW_METRIC] = $mapping['MyPlugin_myNewMetric']; |
| 215 | * } |
| 216 | * |
| 217 | * @ignore |
| 218 | */ |
| 219 | Piwik::postEvent('Metrics.addMetricIdToNameMapping', [&$value]); |
| 220 | |
| 221 | $cache->save($cacheKey, $value); |
| 222 | } |
| 223 | return $value; |
| 224 | } |
| 225 | |
| 226 | public static function getVisitsMetricNames() |
| 227 | { |
| 228 | $names = array(); |
| 229 | |
| 230 | foreach (self::$metricsAggregatedFromLogs as $metricId) { |
| 231 | $names[$metricId] = self::$mappingFromIdToName[$metricId]; |
| 232 | } |
| 233 | |
| 234 | return $names; |
| 235 | } |
| 236 | |
| 237 | public static function getMappingFromNameToId() |
| 238 | { |
| 239 | static $nameToId = null; |
| 240 | if ($nameToId === null) { |
| 241 | $nameToId = array_flip(self::$mappingFromIdToName); |
| 242 | } |
| 243 | return $nameToId; |
| 244 | } |
| 245 | |
| 246 | public static function getMappingFromNameToIdGoal() |
| 247 | { |
| 248 | static $nameToId = null; |
| 249 | if ($nameToId === null) { |
| 250 | $nameToId = array_flip(self::$mappingFromIdToNameGoal); |
| 251 | } |
| 252 | return $nameToId; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Is a lower value for a given column better? |
| 257 | * @param $column |
| 258 | * @return bool |
| 259 | * |
| 260 | * @ignore |
| 261 | */ |
| 262 | public static function isLowerValueBetter($column) |
| 263 | { |
| 264 | $isLowerBetter = null; |
| 265 | |
| 266 | /** |
| 267 | * Use this event to define if a lower value of a metric is better. |
| 268 | * |
| 269 | * @param string $isLowerBetter should be set to a boolean indicating if lower is better |
| 270 | * @param string $column name of the column to determine |
| 271 | * |
| 272 | * **Example** |
| 273 | * |
| 274 | * public function checkIsLowerMetricValueBetter(&$isLowerBetter, $metric) |
| 275 | * { |
| 276 | * if ($metric === 'position') { |
| 277 | * $isLowerBetter = true; |
| 278 | * } |
| 279 | * } |
| 280 | */ |
| 281 | Piwik::postEvent('Metrics.isLowerValueBetter', [&$isLowerBetter, $column]); |
| 282 | |
| 283 | if (!is_null($isLowerBetter)) { |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | $lowerIsBetterPatterns = array( |
| 288 | 'bounce', 'exit' |
| 289 | ); |
| 290 | |
| 291 | foreach ($lowerIsBetterPatterns as $pattern) { |
| 292 | if (strpos($column, $pattern) !== false) { |
| 293 | return true; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Derive the unit name from a column name |
| 302 | * @param $column |
| 303 | * @param $idSite |
| 304 | * @return string |
| 305 | * @ignore |
| 306 | */ |
| 307 | public static function getUnit($column, $idSite) |
| 308 | { |
| 309 | $nameToUnit = array( |
| 310 | '_rate' => '%', |
| 311 | 'revenue' => Site::getCurrencySymbolFor($idSite), |
| 312 | '_time_' => 's' |
| 313 | ); |
| 314 | |
| 315 | $unit = null; |
| 316 | |
| 317 | /** |
| 318 | * Use this event to define units for custom metrics used in evolution graphs and row evolution only. |
| 319 | * |
| 320 | * @param string $unit should hold the unit (e.g. %, €, s or empty string) |
| 321 | * @param string $column name of the column to determine |
| 322 | * @param string $idSite id of the current site |
| 323 | */ |
| 324 | Piwik::postEvent('Metrics.getEvolutionUnit', [&$unit, $column, $idSite]); |
| 325 | |
| 326 | if (!empty($unit)) { |
| 327 | return $unit; |
| 328 | } |
| 329 | |
| 330 | foreach ($nameToUnit as $pattern => $type) { |
| 331 | if (strpos($column, $pattern) !== false) { |
| 332 | return $type; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | return ''; |
| 337 | } |
| 338 | |
| 339 | public static function getDefaultMetricTranslations() |
| 340 | { |
| 341 | $cacheId = CacheId::pluginAware('DefaultMetricTranslations'); |
| 342 | $cache = PiwikCache::getTransientCache(); |
| 343 | |
| 344 | if ($cache->contains($cacheId)) { |
| 345 | return $cache->fetch($cacheId); |
| 346 | } |
| 347 | |
| 348 | $translations = array( |
| 349 | 'label' => 'General_ColumnLabel', |
| 350 | 'date' => 'General_Date', |
| 351 | 'avg_time_on_page' => 'General_ColumnAverageTimeOnPage', |
| 352 | 'sum_time_spent' => 'General_ColumnSumVisitLength', |
| 353 | 'sum_visit_length' => 'General_ColumnSumVisitLength', |
| 354 | 'bounce_count' => 'General_ColumnBounces', |
| 355 | 'bounce_count_returning' => 'VisitFrequency_ColumnBounceCountForReturningVisits', |
| 356 | 'max_actions' => 'General_ColumnMaxActions', |
| 357 | 'max_actions_returning' => 'VisitFrequency_ColumnMaxActionsInReturningVisit', |
| 358 | 'nb_visits_converted_returning' => 'VisitFrequency_ColumnNbReturningVisitsConverted', |
| 359 | 'sum_visit_length_returning' => 'VisitFrequency_ColumnSumVisitLengthReturning', |
| 360 | 'nb_visits_converted' => 'General_ColumnVisitsWithConversions', |
| 361 | 'nb_conversions' => 'Goals_ColumnConversions', |
| 362 | 'revenue' => 'General_ColumnRevenue', |
| 363 | 'nb_hits' => 'General_ColumnPageviews', |
| 364 | 'entry_nb_visits' => 'General_ColumnEntrances', |
| 365 | 'entry_nb_uniq_visitors' => 'General_ColumnUniqueEntrances', |
| 366 | 'exit_nb_visits' => 'General_ColumnExits', |
| 367 | 'exit_nb_uniq_visitors' => 'General_ColumnUniqueExits', |
| 368 | 'entry_bounce_count' => 'General_ColumnBounces', |
| 369 | 'exit_bounce_count' => 'General_ColumnBounces', |
| 370 | 'exit_rate' => 'General_ColumnExitRate', |
| 371 | ); |
| 372 | |
| 373 | $dailySum = ' (' . Piwik::translate('General_DailySum') . ')'; |
| 374 | $afterEntry = ' ' . Piwik::translate('General_AfterEntry'); |
| 375 | |
| 376 | $translations['sum_daily_nb_uniq_visitors'] = Piwik::translate('General_ColumnNbUniqVisitors') . $dailySum; |
| 377 | $translations['sum_daily_nb_users'] = Piwik::translate('General_ColumnNbUsers') . $dailySum; |
| 378 | $translations['sum_daily_entry_nb_uniq_visitors'] = Piwik::translate('General_ColumnUniqueEntrances') . $dailySum; |
| 379 | $translations['sum_daily_exit_nb_uniq_visitors'] = Piwik::translate('General_ColumnUniqueExits') . $dailySum; |
| 380 | $translations['entry_nb_actions'] = Piwik::translate('General_ColumnNbActions') . $afterEntry; |
| 381 | $translations['entry_sum_visit_length'] = Piwik::translate('General_ColumnSumVisitLength') . $afterEntry; |
| 382 | |
| 383 | $translations = array_merge(self::getDefaultMetrics(), self::getDefaultProcessedMetrics(), $translations); |
| 384 | |
| 385 | /** |
| 386 | * Use this event to register translations for metrics processed by your plugin. |
| 387 | * |
| 388 | * @param string $translations The array mapping of column_name => Plugin_TranslationForColumn |
| 389 | */ |
| 390 | Piwik::postEvent('Metrics.getDefaultMetricTranslations', array(&$translations)); |
| 391 | |
| 392 | $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations); |
| 393 | |
| 394 | $cache->save($cacheId, $translations); |
| 395 | |
| 396 | return $translations; |
| 397 | } |
| 398 | |
| 399 | public static function getDefaultMetrics() |
| 400 | { |
| 401 | $cacheId = CacheId::languageAware('DefaultMetrics'); |
| 402 | $cache = PiwikCache::getTransientCache(); |
| 403 | |
| 404 | if ($cache->contains($cacheId)) { |
| 405 | return $cache->fetch($cacheId); |
| 406 | } |
| 407 | |
| 408 | $translations = array( |
| 409 | 'nb_visits' => 'General_ColumnNbVisits', |
| 410 | 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitors', |
| 411 | 'nb_actions' => 'General_ColumnNbActions', |
| 412 | 'nb_users' => 'General_ColumnNbUsers', |
| 413 | ); |
| 414 | $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations); |
| 415 | |
| 416 | $cache->save($cacheId, $translations); |
| 417 | |
| 418 | return $translations; |
| 419 | } |
| 420 | |
| 421 | public static function getDefaultProcessedMetrics() |
| 422 | { |
| 423 | $cacheId = CacheId::languageAware('DefaultProcessedMetrics'); |
| 424 | $cache = PiwikCache::getTransientCache(); |
| 425 | |
| 426 | if ($cache->contains($cacheId)) { |
| 427 | return $cache->fetch($cacheId); |
| 428 | } |
| 429 | |
| 430 | $translations = array( |
| 431 | // Processed in AddColumnsProcessedMetrics |
| 432 | 'nb_actions_per_visit' => 'General_ColumnActionsPerVisit', |
| 433 | 'avg_time_on_site' => 'General_ColumnAvgTimeOnSite', |
| 434 | 'bounce_rate' => 'General_ColumnBounceRate', |
| 435 | 'conversion_rate' => 'General_ColumnConversionRate', |
| 436 | ); |
| 437 | $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations); |
| 438 | |
| 439 | $cache->save($cacheId, $translations); |
| 440 | |
| 441 | return $translations; |
| 442 | } |
| 443 | |
| 444 | public static function getReadableColumnName($columnIdRaw) |
| 445 | { |
| 446 | $mappingIdToName = self::$mappingFromIdToName; |
| 447 | |
| 448 | if (array_key_exists($columnIdRaw, $mappingIdToName)) { |
| 449 | return $mappingIdToName[$columnIdRaw]; |
| 450 | } |
| 451 | |
| 452 | return $columnIdRaw; |
| 453 | } |
| 454 | |
| 455 | public static function getMetricIdsToProcessReportTotal() |
| 456 | { |
| 457 | return array( |
| 458 | self::INDEX_NB_VISITS, |
| 459 | self::INDEX_NB_UNIQ_VISITORS, |
| 460 | self::INDEX_NB_ACTIONS, |
| 461 | self::INDEX_PAGE_NB_HITS, |
| 462 | self::INDEX_NB_VISITS_CONVERTED, |
| 463 | self::INDEX_NB_CONVERSIONS, |
| 464 | self::INDEX_BOUNCE_COUNT, |
| 465 | self::INDEX_PAGE_ENTRY_BOUNCE_COUNT, |
| 466 | self::INDEX_PAGE_ENTRY_NB_VISITS, |
| 467 | self::INDEX_PAGE_ENTRY_NB_ACTIONS, |
| 468 | self::INDEX_PAGE_EXIT_NB_VISITS, |
| 469 | self::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS, |
| 470 | self::INDEX_REVENUE |
| 471 | ); |
| 472 | } |
| 473 | |
| 474 | public static function getDefaultMetricsDocumentation() |
| 475 | { |
| 476 | $cacheId = CacheId::pluginAware('DefaultMetricsDocumentation'); |
| 477 | $cache = PiwikCache::getTransientCache(); |
| 478 | |
| 479 | if ($cache->contains($cacheId)) { |
| 480 | return $cache->fetch($cacheId); |
| 481 | } |
| 482 | |
| 483 | $translations = array( |
| 484 | 'nb_visits' => 'General_ColumnNbVisitsDocumentation', |
| 485 | 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitorsDocumentation', |
| 486 | 'nb_actions' => 'General_ColumnNbActionsDocumentation', |
| 487 | 'nb_users' => 'General_ColumnNbUsersDocumentation', |
| 488 | 'nb_actions_per_visit' => 'General_ColumnActionsPerVisitDocumentation', |
| 489 | 'avg_time_on_site' => 'General_ColumnAvgTimeOnSiteDocumentation', |
| 490 | 'bounce_rate' => 'General_ColumnBounceRateDocumentation', |
| 491 | 'conversion_rate' => 'General_ColumnConversionRateDocumentation', |
| 492 | 'avg_time_on_page' => 'General_ColumnAverageTimeOnPageDocumentation', |
| 493 | 'nb_hits' => 'General_ColumnPageviewsDocumentation', |
| 494 | 'exit_rate' => 'General_ColumnExitRateDocumentation' |
| 495 | ); |
| 496 | |
| 497 | /** |
| 498 | * Use this event to register translations for metrics documentation processed by your plugin. |
| 499 | * |
| 500 | * @param string[] $translations The array mapping of column_name => Plugin_TranslationForColumnDocumentation |
| 501 | */ |
| 502 | Piwik::postEvent('Metrics.getDefaultMetricDocumentationTranslations', array(&$translations)); |
| 503 | |
| 504 | $translations = array_map(array('\\Piwik\\Piwik', 'translate'), $translations); |
| 505 | |
| 506 | $cache->save($cacheId, $translations); |
| 507 | |
| 508 | return $translations; |
| 509 | } |
| 510 | |
| 511 | public static function getPercentVisitColumn() |
| 512 | { |
| 513 | $percentVisitsLabel = str_replace(' ', ' ', Piwik::translate('General_ColumnPercentageVisits')); |
| 514 | return $percentVisitsLabel; |
| 515 | } |
| 516 | } |
| 517 |