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