New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show sparkline evolution figures for visits, goals and ecommerce overviews #19057
Conversation
Work in progress - visits and goals overviews are done, ecommerce renders sparklines a little differently and is not implemented yet. |
The Ecommerce overview spark lines have been implemented using a custom template rather than a visualization, probably to allow special handling for the abandoned cart goal metrics. There isn't enough time allocated for this issue to rework the overview to use a visualization, so instead I've chosen a pragmatic approach and rendered the evolution values in the custom spark line template. This isn't ideal but didn't take much time and will provide evolution metrics in one of the more useful places until things can be reworked at some future time. In order for the override method |
This issue is in "needs review" but there has been no activity for 7 days. ping @matomo-org/core-reviewers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a rough look through the changes. The approach looks fine, but we might have a similar issue like we had a plenty of times before. We always request the data formatted from the API and afterwards try to compare the data. That often fails for languages that use other formattings than english. I guess at some point we need to decide to put a lot more effort into that topic and start changing that behavior to request unformatted data and format it when it is shown. Not sure if we should do that now. But I'm pretty sure that for some languages this new evolutions might show incorrect values....
if ($columnName == 'avg_time_on_site') { | ||
// TODO Unable to calculate this evolution because the visit summary archive stores the time pre-formatted. | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess to get this and other metrics to work we would need to request the data with format_metrics=0
and format the metrics manually before they are displayed. This might need a bit more effort but would also fix some other issues that might currently occur when formatted values are compared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've committed a change which makes sparkline API calls with the format_metrics=0
parameter, this seems to be working well and the compute_evolution()
callback now received unformatted data allowing time, percent and money metrics to be safely calculated.
The main sparkline visualization CoreVisualizations\Visualizations\Sparklines
has been updated to format the sparkline values using the appropriate Metric class retrieved from the report.
The goals and visits summary overview reports have been updated to format the sparkline evolution tooltips by finding the Metric object for the column and using it's format method.
Ecommerce doesn't use a report or visualization and as noted before it needs some rework. For now I've done a quick fix to manually format the metrics by name.
The bandwidth plugin was pushing values into the datatable pre-formatted, so I've committed a change there to provide unformatted values instead and also added a new Metric class for formatting the overall bandwidth metric. It seems to be working well on the visit summary overview.
…back method extra parameter documentation
…into m-10716-evolution-on-overviews
…g added to the sparkline visualization and overview reports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already goes in the right direction, but there are still a couple of issues with the latest changes.
plugins/CoreVisualizations/Visualizations/Sparklines/Config.php
Outdated
Show resolved
Hide resolved
…sualization loadDataTableFromAPI methods
…le and Visualization classes
@sgiehl Thanks for fixing the bandwidth metrics, that's looking really good 😃 Not sure if you want to do a quick final review or shall I go ahead and merge? |
@bx80 I have merge in the latest changed from |
@bx80 Seems you need to have another look at that one. The number formatting seems to fail when comparing data. I was able to reproduce that locally. |
@sgiehl I'm not able to see where the number formatting is failing, the failed UI tests all seem to be caused by the action data tables not grouping and when I run this test locally they group correctly. I've also checked all the obvious places in the UI both in English and Deutsch (in case it's locale specific) but the sparkline tooltips number comparisons seem to be formatted correctly. I'm clearly missing something, where should I be looking? 👀 |
Are the average spent time and bounce rate metric formatted for you? |
As mentioned before it seems only broken in comparison mode. So when comparing dates or segments. |
@sgiehl Sorry, I was thinking comparing via the tooltips not via comparison mode. 🤦♂️ I see the issue now and I've commit a fix to also the format metrics when the sparklines are in comparison mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some more small issues that don't work properly. Will try to push some fixes for it, so we can go on and merge this issue soon
plugins/Goals/Reports/Get.php
Outdated
$lastPeriod = PeriodFactory::build(Piwik::getPeriod(), $lastPeriodDate); | ||
$lastPrettyDate = ($currentPeriod instanceof Month ? $lastPeriod->getLocalizedLongString() : $lastPeriod->getPrettyString()); | ||
|
||
$view->config->compute_evolution = function ($columns, $metrics) use ($currentPrettyDate, $lastPrettyDate, $previousDataRow) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There currently seems to be a problem with overall revenue. There is no evolution calculated for it. Guess the problem is, that the column is formatted using a filter above. And so it isn't numeric here anymore...
@@ -202,9 +230,21 @@ private function fetchConfiguredSparklines() | |||
|
|||
list($compareValues, $compareDescriptions, $evolutions) = $this->getValuesAndDescriptions($compareRow, $columnToUse, '_change', '_trend'); | |||
|
|||
$metricsObjs = $report->getProcessedMetricsById(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess using Report::getProcessedMetricsForTable
would be more accurate.
foreach ($metricsObjs as $metricObj) { | ||
if ((is_array($column) && in_array($metricObj->getName(), ($column)) || $metricObj->getName() == $column)) { | ||
$valueFormatted = $metricObj->format($value, $formatter); | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finding the correct metric for formatting can be done outside the nested foreach loops, no need to do that over and over again. Also this is actually not always accurate. Their can be multiple columns given, which might not necessarily have the same format. e.g. it could be a percent and money value. Currently both metrics would be formatted with the first matching one. Guess we need to format each separately...
foreach ($metricsObjs as $metricObj) { | ||
if ((is_array($column) && in_array($metricObj->getName(), ($column)) || $metricObj->getName() == $column)) { | ||
$valueFormatted = $metricObj->format($value, $formatter); | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
cc57e97
to
f36e398
Compare
@bx80 with the fixes I've pushed, I think this should be good to merge now. Feel free to have another quick look at the changes and merge it if they look fine for you. Btw. before merging this one, you need to merge all related submodule PRs and update the submodules in this PR back to their 4.x-dev branch again. Otherwise we might get submodule reference issues.... |
Description:
Fixes #10716
This PR adds evolution percentages and up/down icons to the end of the sparklines shown on the overview screens for visits, goals and ecommerce.
Review