|
13 | 13 | use Piwik\Columns\Dimension; |
14 | 14 | use Piwik\Columns\MetricsList; |
15 | 15 | use Piwik\Common; |
| 16 | +use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal; |
16 | 17 | use Piwik\Piwik; |
17 | 18 | use Piwik\Plugin\ArchivedMetric; |
18 | 19 | use Piwik\Plugin\ComputedMetric; |
@@ -295,24 +296,92 @@ public function getReportMetadataEnd(&$reports, $info) |
295 | 296 | 'revenue' => Dimension::TYPE_MONEY, |
296 | 297 | ]; |
297 | 298 |
|
| 299 | + // special goal metrics for Actions page reports |
| 300 | + $pageGoalMetrics = array_merge($goalMetrics, [ |
| 301 | + 'nb_conversions_attrib' => Piwik::translate('Goals_ColumnConversions'), |
| 302 | + 'revenue_attrib' => Piwik::translate('General_ColumnRevenue'), |
| 303 | + ]); |
| 304 | + unset($pageGoalMetrics['revenue']); |
| 305 | + |
| 306 | + $pageGoalProcessedMetrics = array_merge($goalProcessedMetrics, [ |
| 307 | + 'nb_conversions_page_rate' => Piwik::translate('Goals_ConversionRatePageViewedBeforeGeneric'), |
| 308 | + ]); |
| 309 | + |
| 310 | + $pageGoalMetricTypes = array_merge($goalMetricTypes, [ |
| 311 | + 'nb_conversions_attrib' => Dimension::TYPE_NUMBER, |
| 312 | + 'revenue_attrib' => Dimension::TYPE_MONEY, |
| 313 | + 'nb_conversions_page_rate' => Dimension::TYPE_PERCENT, |
| 314 | + ]); |
| 315 | + unset($pageGoalMetricTypes['revenue']); |
| 316 | + |
| 317 | + // special goal metrics for Actions entry page reports |
| 318 | + $entryPageGoalMetrics = array_merge($goalMetrics, [ |
| 319 | + 'nb_conversions_entry' => Piwik::translate('Goals_ColumnConversions'), |
| 320 | + 'revenue_entry' => Piwik::translate('General_ColumnRevenue'), |
| 321 | + ]); |
| 322 | + unset($entryPageGoalMetrics['revenue']); |
| 323 | + |
| 324 | + $entryPageGoalProcessedMetrics = array_merge($goalProcessedMetrics, [ |
| 325 | + 'revenue_per_entry' => Piwik::translate('General_ColumnValuePerEntry'), |
| 326 | + 'nb_conversions_entry_rate' => Piwik::translate('General_ColumnConversionRate'), |
| 327 | + ]); |
| 328 | + |
| 329 | + $entryPageGoalMetricTypes = array_merge($goalMetricTypes, [ |
| 330 | + 'nb_conversions_entry' => Dimension::TYPE_NUMBER, |
| 331 | + 'revenue_entry' => Dimension::TYPE_MONEY, |
| 332 | + 'revenue_per_entry' => Dimension::TYPE_NUMBER, |
| 333 | + 'nb_conversions_entry_rate' => Dimension::TYPE_PERCENT, |
| 334 | + ]); |
| 335 | + unset($entryPageGoalMetricTypes['revenue']); |
| 336 | + |
| 337 | + // add ecommerce metrics if idGoal is an ecommerce goal |
| 338 | + $idGoal = \Piwik\Request::fromRequest()->getParameter('idGoal', ''); |
| 339 | + if ($idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER || $idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) { |
| 340 | + $extraEcommerceProcessedMetrics = [ |
| 341 | + 'avg_order_revenue' => Piwik::translate('General_AverageOrderValue'), |
| 342 | + 'items' => Piwik::translate('General_PurchasedProducts'), |
| 343 | + ]; |
| 344 | + |
| 345 | + $extraEcommerceMetricTypes = [ |
| 346 | + 'avg_order_revenue' => Dimension::TYPE_MONEY, |
| 347 | + 'itmes' => Dimension::TYPE_NUMBER, |
| 348 | + ]; |
| 349 | + |
| 350 | + $pageGoalProcessedMetrics = array_merge($pageGoalProcessedMetrics, $extraEcommerceProcessedMetrics); |
| 351 | + $entryPageGoalProcessedMetrics = array_merge($entryPageGoalProcessedMetrics, $extraEcommerceProcessedMetrics); |
| 352 | + |
| 353 | + $pageGoalMetricTypes = array_merge($pageGoalMetricTypes, $extraEcommerceMetricTypes); |
| 354 | + $entryPageGoalMetricTypes = array_merge($entryPageGoalMetricTypes, $extraEcommerceMetricTypes); |
| 355 | + } |
| 356 | + |
298 | 357 | $reportsWithGoals = self::getAllReportsWithGoalMetrics(); |
299 | 358 |
|
300 | 359 | foreach ($reportsWithGoals as $reportWithGoals) { |
| 360 | + $goalMetricsToUse = $goalMetrics; |
| 361 | + $goalProcessedMetricsToUse = $goalProcessedMetrics; |
| 362 | + $goalMetricTypesToUse = $goalMetricTypes; |
| 363 | + |
| 364 | + $request = $reportWithGoals['module'] . '.' . $reportWithGoals['action']; |
| 365 | + if (in_array($request, AddColumnsProcessedMetricsGoal::ACTIONS_PAGE_REPORTS_WITH_GOAL_METRICS)) { |
| 366 | + $goalMetricsToUse = $pageGoalMetrics; |
| 367 | + $goalProcessedMetricsToUse = $pageGoalProcessedMetrics; |
| 368 | + $goalMetricTypesToUse = $pageGoalMetricTypes; |
| 369 | + } else if (in_array($request, AddColumnsProcessedMetricsGoal::ACTIONS_ENTRY_PAGE_REPORTS_WITH_GOAL_METRICS)) { |
| 370 | + $goalMetricsToUse = $entryPageGoalMetrics; |
| 371 | + $goalProcessedMetricsToUse = $entryPageGoalProcessedMetrics; |
| 372 | + $goalMetricTypesToUse = $entryPageGoalMetricTypes; |
| 373 | + } |
| 374 | + |
301 | 375 | // Select this report from the API metadata array |
302 | 376 | // and add the Goal metrics to it |
303 | 377 | foreach ($reports as &$apiReportToUpdate) { |
304 | | - // We do not add anything for Action reports, as no overall metrics are processed there at the moment |
305 | | - if ($apiReportToUpdate['module'] === 'Actions') { |
306 | | - continue; |
307 | | - } |
308 | | - |
309 | 378 | if ($apiReportToUpdate['module'] == $reportWithGoals['module'] |
310 | 379 | && $apiReportToUpdate['action'] == $reportWithGoals['action'] |
311 | 380 | && empty($apiReportToUpdate['parameters']) |
312 | 381 | ) { |
313 | | - $apiReportToUpdate['metricsGoal'] = $goalMetrics; |
314 | | - $apiReportToUpdate['processedMetricsGoal'] = $goalProcessedMetrics; |
315 | | - $apiReportToUpdate['metricTypesGoal'] = $goalMetricTypes; |
| 382 | + $apiReportToUpdate['metricsGoal'] = $goalMetricsToUse; |
| 383 | + $apiReportToUpdate['processedMetricsGoal'] = $goalProcessedMetricsToUse; |
| 384 | + $apiReportToUpdate['metricTypesGoal'] = $goalMetricTypesToUse; |
316 | 385 | break; |
317 | 386 | } |
318 | 387 | } |
|
0 commit comments