Skip to content
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

Merged
merged 33 commits into from May 24, 2022

Conversation

bx80
Copy link
Contributor

@bx80 bx80 commented Apr 6, 2022

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

@bx80 bx80 added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Apr 6, 2022
@bx80 bx80 added this to the 4.10.0 milestone Apr 6, 2022
@bx80 bx80 self-assigned this Apr 6, 2022
@bx80
Copy link
Contributor Author

bx80 commented Apr 6, 2022

Work in progress - visits and goals overviews are done, ecommerce renders sparklines a little differently and is not implemented yet.

@bx80
Copy link
Contributor Author

bx80 commented Apr 11, 2022

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 Ecommerce.getMetricsForGoal() to gain access to the data row used in the parent Goals.getMetricsForGoal() I've added an optional parameter to the parent method to allow the preloaded data row to be passed by the child method. I thought this preferable to replicating the entire parent method, but open to better ideas! 🙂

@bx80 bx80 added the Needs Review PRs that need a code review label Apr 11, 2022
@github-actions
Copy link
Contributor

This issue is in "needs review" but there has been no activity for 7 days. ping @matomo-org/core-reviewers

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Apr 19, 2022
Copy link
Member

@sgiehl sgiehl left a 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....

plugins/Goals/Reports/Get.php Outdated Show resolved Hide resolved
plugins/VisitsSummary/Reports/Get.php Outdated Show resolved Hide resolved
Comment on lines 130 to 133
if ($columnName == 'avg_time_on_site') {
// TODO Unable to calculate this evolution because the visit summary archive stores the time pre-formatted.
return;
}
Copy link
Member

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.

Copy link
Contributor Author

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.

plugins/CoreVisualizations/Visualizations/Sparklines.php Outdated Show resolved Hide resolved
plugins/VisitsSummary/Reports/Get.php Outdated Show resolved Hide resolved
@sgiehl sgiehl removed the Needs Review PRs that need a code review label Apr 27, 2022
…g added to the sparkline visualization and overview reports
@bx80 bx80 added Needs Review PRs that need a code review and removed Stale The label used by the Close Stale Issues action labels Apr 28, 2022
Copy link
Member

@sgiehl sgiehl left a 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.

core/ViewDataTable/Request.php Outdated Show resolved Hide resolved
plugins/CoreVisualizations/Visualizations/Sparklines.php Outdated Show resolved Hide resolved
plugins/Ecommerce/Controller.php Outdated Show resolved Hide resolved
plugins/Ecommerce/templates/getSparklines.twig Outdated Show resolved Hide resolved
plugins/Ecommerce/Controller.php Show resolved Hide resolved
@sgiehl sgiehl removed the Needs Review PRs that need a code review label Apr 28, 2022
plugins/MediaAnalytics/Visualizations/MediaEvolution.php Outdated Show resolved Hide resolved
plugins/Ecommerce/Controller.php Show resolved Hide resolved
plugins/Ecommerce/templates/getSparklines.twig Outdated Show resolved Hide resolved
plugins/CoreVisualizations/Visualizations/Sparklines.php Outdated Show resolved Hide resolved
@bx80
Copy link
Contributor Author

bx80 commented May 18, 2022

@sgiehl Thanks for fixing the bandwidth metrics, that's looking really good 😃
I don't think I'm going to have the time to rework the ecommerce sparklines for this release.
I've tidied up the remaining tests.

Not sure if you want to do a quick final review or shall I go ahead and merge?

@sgiehl
Copy link
Member

sgiehl commented May 18, 2022

@bx80 I have merge in the latest changed from 4.x-dev to see if any tests are still failing. But looking through the changed UI tests it seems like the numbers for the sparklines aren't formatted anymore when comparing data. Haven't looked in detail yet. I will wait for the tests to finish, maybe they only need to be updated 🤔

@sgiehl
Copy link
Member

sgiehl commented May 18, 2022

@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.

@bx80
Copy link
Contributor Author

bx80 commented May 19, 2022

@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? 👀

@sgiehl
Copy link
Member

sgiehl commented May 19, 2022

Are the average spent time and bounce rate metric formatted for you?

@bx80
Copy link
Contributor Author

bx80 commented May 19, 2022

Are the average spent time and bounce rate metric formatted for you?

Yes, they seem ok.
image
image
image

@sgiehl
Copy link
Member

sgiehl commented May 20, 2022

As mentioned before it seems only broken in comparison mode. So when comparing dates or segments.

@bx80
Copy link
Contributor Author

bx80 commented May 21, 2022

@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.
image

Copy link
Member

@sgiehl sgiehl left a 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

$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) {
Copy link
Member

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();
Copy link
Member

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.

Comment on lines 239 to 244
foreach ($metricsObjs as $metricObj) {
if ((is_array($column) && in_array($metricObj->getName(), ($column)) || $metricObj->getName() == $column)) {
$valueFormatted = $metricObj->format($value, $formatter);
break;
}
}
Copy link
Member

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...

Comment on lines 282 to 287
foreach ($metricsObjs as $metricObj) {
if ((is_array($column) && in_array($metricObj->getName(), ($column)) || $metricObj->getName() == $column)) {
$valueFormatted = $metricObj->format($value, $formatter);
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@sgiehl sgiehl force-pushed the m-10716-evolution-on-overviews branch from cc57e97 to f36e398 Compare May 23, 2022 13:55
@sgiehl
Copy link
Member

sgiehl commented May 23, 2022

@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.
Regarding the ecommerce sparkline refactoring. Found this issue #15349, which we should handle that in.

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....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show sparkline evolution figures for visits, goals and ecommerce overviews
3 participants