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

Disable features that are inaccurate if visit data is not profilable #16773

Open
wants to merge 120 commits into
base: 4.x-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
cb6daac
add nb_profilable core metricc
diosmosis Oct 29, 2020
aa1d459
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Oct 30, 2020
193c0e8
implement requiresProfilableVisitors() in some reports and use to dis…
diosmosis Oct 30, 2020
6bef1e6
disable returning/new visitors on visitor log based on whether visito…
diosmosis Oct 31, 2020
203d9d7
take userid into account as well
diosmosis Oct 31, 2020
60d6af3
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Nov 10, 2020
d7345ed
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Nov 10, 2020
bd15cda
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Nov 16, 2020
939f6e3
code for marking segments as requiring profilable data and hiding them
diosmosis Nov 16, 2020
22300fb
default value
diosmosis Nov 18, 2020
b3cd71c
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Nov 21, 2020
8977dd4
do not show unique visitors in sparklines if current data is not prof…
diosmosis Nov 21, 2020
ec7d33e
do not show reports that are disabled in widget containers
diosmosis Nov 21, 2020
6df46dc
go through segments and disable some based on having profilable data …
diosmosis Nov 21, 2020
1a1b3b3
change Report::requiresProfilableVisitors() method name and disable r…
diosmosis Nov 22, 2020
be876af
delete columns in API response if not profilable
diosmosis Nov 22, 2020
3f37ae3
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Nov 23, 2020
3e603c8
start on automated test
diosmosis Nov 23, 2020
0f54f90
add another visit to fixture
diosmosis Nov 23, 2020
9cc29a3
allow nb_profilable to be saved even if it is zero so we can differen…
diosmosis Nov 27, 2020
1833576
test more APIs
diosmosis Nov 30, 2020
a077880
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Dec 7, 2020
909f772
finish UI test
diosmosis Dec 7, 2020
4d9d066
some docs
diosmosis Dec 10, 2020
edf1b17
clear some todo
diosmosis Dec 10, 2020
130419a
Handle multi site/period in API when showing non-profilable data.
diosmosis Dec 10, 2020
6843c1f
remove TODO
diosmosis Dec 10, 2020
afa6503
more TODO docs
diosmosis Dec 10, 2020
ca91a39
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Dec 10, 2020
de80d92
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Dec 14, 2020
f7dda63
in tests disable profilable check by default
diosmosis Dec 15, 2020
f044c4b
update expected test files
diosmosis Dec 15, 2020
74d09ea
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Dec 17, 2020
f9d3993
update more expected files
diosmosis Dec 17, 2020
dd5a6bf
fix some tests
diosmosis Dec 18, 2020
a9c4d22
fix test
diosmosis Dec 18, 2020
d93b345
fix more tests
diosmosis Dec 18, 2020
728c3d5
fix more tests
diosmosis Dec 18, 2020
74f5db1
fix more tests
diosmosis Dec 18, 2020
2c27a98
more test fixing
diosmosis Dec 18, 2020
21de72d
update expected screenshots
diosmosis Dec 18, 2020
02ca3d4
condition tweak
diosmosis Dec 20, 2020
e45f361
fill out / remove some TODO
diosmosis Dec 21, 2020
7949371
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Jan 17, 2021
7836482
do not need second condition for summing profilable count
diosmosis Jan 17, 2021
c3f21ce
put transient cache in Request method instead of VisitsSummary.isProf…
diosmosis Jan 17, 2021
6555968
fix segment use
diosmosis Jan 17, 2021
d3579bd
tweak template since key may not be present
diosmosis Jan 17, 2021
2e944ab
apply some more review feedback
diosmosis Jan 18, 2021
ecd256e
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Aug 10, 2021
6d83b61
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Aug 28, 2021
3f48e0c
applying some pr feedback
diosmosis Aug 28, 2021
cb630cb
apply some more review feedback
diosmosis Aug 28, 2021
2721ef9
apply more review feedback
diosmosis Aug 29, 2021
2d4c7ee
add test for segment method
diosmosis Aug 29, 2021
ce6534f
fix a test error
diosmosis Aug 29, 2021
2c84a17
modify UI tests for new code changes
diosmosis Aug 29, 2021
3a84121
update expected tests
diosmosis Aug 29, 2021
36bbccb
update submodules
diosmosis Aug 29, 2021
c0d2262
update expected screenshots
diosmosis Aug 29, 2021
8fbcd7e
update expected files again
diosmosis Aug 29, 2021
b8ff9d4
update submodule
diosmosis Aug 29, 2021
78093a6
fix more tests
diosmosis Aug 29, 2021
79355ac
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Aug 31, 2021
08c1608
more fixes + better warning for some visit frequency widgets
diosmosis Aug 31, 2021
ba5d50f
show message if not profilable and showing goals conversion info
diosmosis Aug 31, 2021
455685c
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Aug 31, 2021
1713914
add nb_profilable core metricc
diosmosis Oct 29, 2020
a686a65
implement requiresProfilableVisitors() in some reports and use to dis…
diosmosis Oct 30, 2020
e3942cc
disable returning/new visitors on visitor log based on whether visito…
diosmosis Oct 31, 2020
d3875a9
take userid into account as well
diosmosis Oct 31, 2020
d0528ff
code for marking segments as requiring profilable data and hiding them
diosmosis Nov 16, 2020
7b8b8e8
default value
diosmosis Nov 18, 2020
5247254
do not show unique visitors in sparklines if current data is not prof…
diosmosis Nov 21, 2020
48532ca
do not show reports that are disabled in widget containers
diosmosis Nov 21, 2020
9213ad3
go through segments and disable some based on having profilable data …
diosmosis Nov 21, 2020
7420ec7
change Report::requiresProfilableVisitors() method name and disable r…
diosmosis Nov 22, 2020
6920256
delete columns in API response if not profilable
diosmosis Nov 22, 2020
cc5f582
start on automated test
diosmosis Nov 23, 2020
7418a98
add another visit to fixture
diosmosis Nov 23, 2020
122fb74
allow nb_profilable to be saved even if it is zero so we can differen…
diosmosis Nov 27, 2020
ab82c21
test more APIs
diosmosis Nov 30, 2020
dc14820
finish UI test
diosmosis Dec 7, 2020
26eb2a2
some docs
diosmosis Dec 10, 2020
8757e25
clear some todo
diosmosis Dec 10, 2020
4289b9d
Handle multi site/period in API when showing non-profilable data.
diosmosis Dec 10, 2020
4a4e571
remove TODO
diosmosis Dec 10, 2020
69711ae
more TODO docs
diosmosis Dec 10, 2020
b6c7996
in tests disable profilable check by default
diosmosis Dec 15, 2020
c140fd7
update expected test files
diosmosis Dec 15, 2020
4179989
update more expected files
diosmosis Dec 17, 2020
61a5f9f
fix some tests
diosmosis Dec 18, 2020
84d3d8e
fix test
diosmosis Dec 18, 2020
994da69
fix more tests
diosmosis Dec 18, 2020
4295506
fix more tests
diosmosis Dec 18, 2020
9e13c69
fix more tests
diosmosis Dec 18, 2020
f1f6ddd
more test fixing
diosmosis Dec 18, 2020
5a517c6
update expected screenshots
diosmosis Dec 18, 2020
24efff8
condition tweak
diosmosis Dec 20, 2020
675b382
fill out / remove some TODO
diosmosis Dec 21, 2020
986624d
do not need second condition for summing profilable count
diosmosis Jan 17, 2021
6659c48
put transient cache in Request method instead of VisitsSummary.isProf…
diosmosis Jan 17, 2021
49587b1
fix segment use
diosmosis Jan 17, 2021
3996bf6
tweak template since key may not be present
diosmosis Jan 17, 2021
3276bf1
apply some more review feedback
diosmosis Jan 18, 2021
7fe1b1d
applying some pr feedback
diosmosis Aug 28, 2021
173deaa
apply some more review feedback
diosmosis Aug 28, 2021
d345160
apply more review feedback
diosmosis Aug 29, 2021
33f8625
add test for segment method
diosmosis Aug 29, 2021
524adb6
fix a test error
diosmosis Aug 29, 2021
277018c
modify UI tests for new code changes
diosmosis Aug 29, 2021
b372c39
update expected tests
diosmosis Aug 29, 2021
0694bb4
update expected screenshots
diosmosis Aug 29, 2021
07fe8fb
update expected files again
diosmosis Aug 29, 2021
792d7aa
fix more tests
diosmosis Aug 29, 2021
440bdb0
more fixes + better warning for some visit frequency widgets
diosmosis Aug 31, 2021
24e23c2
show message if not profilable and showing goals conversion info
diosmosis Aug 31, 2021
6636838
fix php cs & apply some PSR12 code formatting
sgiehl May 9, 2022
f439985
Merge branch '4.x-dev' into 16363-profilable-disable-features
diosmosis Sep 1, 2022
e4367a6
Merge branch '16363-profilable-disable-features' of github.com:matomo…
diosmosis Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions config/environment/test.php
Expand Up @@ -135,5 +135,6 @@
})),
)),

'tests.isProfilableCheckDisabled' => true,
'test.vars.forceCliMultiViaCurl' => false,
);
46 changes: 46 additions & 0 deletions core/API/DataTablePostProcessor.php
Expand Up @@ -12,16 +12,20 @@
use Piwik\API\DataTableManipulator\Flattener;
use Piwik\API\DataTableManipulator\LabelFilter;
use Piwik\API\DataTableManipulator\ReportTotalsCalculator;
use Piwik\Archive\DataTableFactory;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\DataTableInterface;
use Piwik\DataTable\Filter\PivotByDimension;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Plugin\Report;
use Piwik\Plugin\ReportsProvider;
use Piwik\Plugins\API\Filter\DataComparisonFilter;
use Piwik\Site;

/**
* Processes DataTables that should be served through Piwik's APIs. This processing handles
Expand Down Expand Up @@ -132,11 +136,53 @@ public function process(DataTableInterface $dataTable)
$dataTable = $this->convertSegmentValueToSegment($dataTable);
$dataTable = $this->applyQueuedFilters($dataTable);
$dataTable = $this->applyRequestedColumnDeletion($dataTable);
$dataTable = $this->removeMetricsIfNotProfilable($dataTable);
$dataTable = $this->applyLabelFilter($dataTable);
$dataTable = $this->applyMetricsFormatting($dataTable);
return $dataTable;
}

private function removeMetricsIfNotProfilable(DataTableInterface $dataTable)
{
$dataTable->filter(function (DataTable $table) {
/** @var Site $site */
$site = $table->getMetadata('site');

/** @var Period $period */
$period = $table->getMetadata('period');

$segment = $table->getMetadata(DataTableFactory::TABLE_METADATA_SEGMENT_INDEX);

if (empty($site)
|| empty($period)
) {
return;
}

if (Request::isCurrentPeriodProfilable($site->getId(), $period->getLabel(), $period->getDateStart()->toString(), $segment)) {
return;
}

$metricsToRemove = [
Metrics::INDEX_NB_UNIQ_VISITORS,
Metrics::INDEX_SUM_DAILY_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_ENTRY_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_EXIT_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_ENTRY_SUM_DAILY_NB_UNIQ_VISITORS,
Metrics::INDEX_PAGE_EXIT_SUM_DAILY_NB_UNIQ_VISITORS,
];

$metricIdToNameMap = Metrics::getMappingFromIdToName();
foreach (array_values($metricsToRemove) as $indexMetric) {
$metricsToRemove[] = $metricIdToNameMap[$indexMetric];
}

$table->filter(DataTable\Filter\ColumnDelete::class, [$metricsToRemove]);
});

return $dataTable;
}

private function convertSegmentValueToSegment(DataTableInterface $dataTable)
{
$dataTable->filter('AddSegmentBySegmentValue', array($this->report));
Expand Down
58 changes: 58 additions & 0 deletions core/API/Request.php
Expand Up @@ -9,6 +9,7 @@
namespace Piwik\API;

use Exception;
use Matomo\Cache\Transient;
use Piwik\Access;
use Piwik\Cache;
use Piwik\Common;
Expand All @@ -18,9 +19,11 @@
use Piwik\DataTable;
use Piwik\Exception\PluginDeactivatedException;
use Piwik\IP;
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Plugins\CoreHome\LoginAllowlist;
use Piwik\Segment;
use Piwik\SettingsServer;
use Piwik\Url;
use Piwik\UrlHelper;
Expand Down Expand Up @@ -701,4 +704,59 @@ private function shouldDisablePostProcessing()

return $shouldDisable;
}

public static function isCurrentPeriodProfilable($idSite = null, $period = null, $date = null, $segment = null)
{
if (self::isProfilableCheckDisabledInTests()) {
return true;
}

$idSite = $idSite ?: Common::getRequestVar('idSite', $default = false);
$period = $period ?: Common::getRequestVar('period', $default = false);
diosmosis marked this conversation as resolved.
Show resolved Hide resolved
$date = $date ?: Common::getRequestVar('date', $default = false);
$segment = $segment ?: Request::getRawSegmentFromRequest();

if ($idSite === false
|| $period === false
|| $date === false
|| !is_numeric($idSite)
|| Period::isMultiplePeriod($date, $period)
) {
return true;
}

$transientCache = StaticContainer::get(Transient::class);

$segmentObj = new Segment($segment, [$idSite]);

$cacheKey = "VisitsSummary.isProfilable.$idSite.$period.$date." . $segmentObj->getHash();
if (!$transientCache->contains($cacheKey)) {
$isProfilable = Request::processRequest('VisitsSummary.isProfilable', [
'idSite' => $idSite,
'period' => $period,
'date' => $date,
'segment' => $segment,
]);

$transientCache->save($cacheKey, $isProfilable);
} else {
$isProfilable = (bool)$transientCache->fetch($cacheKey);
}

return $isProfilable;
}

private static function isProfilableCheckDisabledInTests()
{
if (!defined('PIWIK_TEST_MODE')) {
return false;
}

try {
$isDisabled = (bool) StaticContainer::get('tests.isProfilableCheckDisabled');
return $isDisabled;
} catch (\Exception $ex) {
return false;
}
}
}
2 changes: 1 addition & 1 deletion core/Archive.php
Expand Up @@ -522,7 +522,7 @@ protected function get($archiveNames, $archiveDataType, $idSubtable = null)
* query archive tables for IDs w/o launching archiving, or launch archiving and
* get the idarchive from ArchiveProcessor instances.
*
* @param string $archiveNames
* @param string[] $archiveNames
* @return array
*/
private function getArchiveIds($archiveNames)
Expand Down
1 change: 1 addition & 0 deletions core/Archive/DataCollection.php
Expand Up @@ -112,6 +112,7 @@ public function __construct($dataNames, $dataType, $sitesId, $periods, $segment,

if ($defaultRow === null) {
$defaultRow = array_fill_keys($dataNames, 0);
unset($defaultRow['nb_profilable']); // for this special metric, we want to know when it was never present
}

$this->sitesId = $sitesId;
Expand Down
18 changes: 18 additions & 0 deletions core/Columns/Dimension.php
Expand Up @@ -192,6 +192,11 @@ abstract class Dimension
*/
protected $metricId = '';

/**
* @var bool
*/
private $isRequiresProfilableData = false;

/**
* To be implemented when a column references another column
* @return Join|null
Expand Down Expand Up @@ -857,4 +862,17 @@ public function getVersion()
return $this->columnType;
}

/**
* Returns true if this dimension requires profilable visit data in order to be useful.
* Dimensions that require profilable data are hidden (as are their associated reports)
* when we find that a specific period contains a majority of un-profilable tracked data.
*
* Derived classes should set the $isRequiresProfilableData member if they are not profilable.
*
* @return mixed
*/
public function isRequiresProfilableData()
{
return $this->isRequiresProfilableData;
}
}
2 changes: 2 additions & 0 deletions core/Columns/DimensionSegmentFactory.php
Expand Up @@ -114,6 +114,8 @@ public function createSegment(Segment $segment = null)
$segment->setRequiresRegisteredUser(true);
}

$segment->setRequiresProfilableData($dimension->isRequiresProfilableData());

return $segment;
}

Expand Down
7 changes: 4 additions & 3 deletions core/DataAccess/ArchiveWriter.php
Expand Up @@ -211,8 +211,8 @@ private function batchInsertSpool($valueType)

$valueSeen = false;
foreach ($records as $record) {
// don't record zero
if (empty($record[1])) {
// don't record zero unless it's nb_profilable
if (empty($record[1]) && $record[0] != 'nb_profilable') {
continue;
}

Expand Down Expand Up @@ -251,7 +251,8 @@ private function batchInsertSpool($valueType)
*/
public function insertRecord($name, $value)
{
if ($this->isRecordZero($value)) {
// NOTE: we allow nb_profilable to be there since periods before nb_profilable was archived will not have the data, and we want to know the difference
if ($this->isRecordZero($value) && $name != 'nb_profilable') {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions core/DataAccess/LogAggregator.php
Expand Up @@ -423,6 +423,7 @@ protected function getVisitsMetricFields()
Metrics::INDEX_BOUNCE_COUNT => "sum(case " . self::LOG_VISIT_TABLE . ".visit_total_actions when 1 then 1 when 0 then 1 else 0 end)",
Metrics::INDEX_NB_VISITS_CONVERTED => "sum(case " . self::LOG_VISIT_TABLE . ".visit_goal_converted when 1 then 1 else 0 end)",
Metrics::INDEX_NB_USERS => "count(distinct " . self::LOG_VISIT_TABLE . ".user_id)",
Metrics::INDEX_NB_PROFILABLE => "sum(" . self::LOG_VISIT_TABLE . ".profilable)",
);
}

Expand Down
1 change: 0 additions & 1 deletion core/DataTable/Filter/ColumnDelete.php
Expand Up @@ -170,7 +170,6 @@ protected function removeColumnsFromTable(&$table)
}

foreach ($this->columnsToRemove as $column) {

if (is_array($row)) {
if (!array_key_exists($column, $row)) {
continue;
Expand Down
3 changes: 3 additions & 0 deletions core/Metrics.php
Expand Up @@ -40,6 +40,7 @@ class Metrics
const INDEX_REVENUE = 9;
const INDEX_GOALS = 10;
const INDEX_SUM_DAILY_NB_UNIQ_VISITORS = 11;
const INDEX_NB_PROFILABLE = 44;

// Specific to the Actions reports
const INDEX_PAGE_NB_HITS = 12;
Expand Down Expand Up @@ -114,6 +115,7 @@ class Metrics
Metrics::INDEX_GOALS => 'goals',
Metrics::INDEX_SUM_DAILY_NB_UNIQ_VISITORS => 'sum_daily_nb_uniq_visitors',
Metrics::INDEX_SUM_DAILY_NB_USERS => 'sum_daily_nb_users',
Metrics::INDEX_NB_PROFILABLE => 'nb_profilable',

// Actions metrics
Metrics::INDEX_PAGE_NB_HITS => 'nb_hits',
Expand Down Expand Up @@ -174,6 +176,7 @@ class Metrics
Metrics::INDEX_SUM_VISIT_LENGTH,
Metrics::INDEX_BOUNCE_COUNT,
Metrics::INDEX_NB_VISITS_CONVERTED,
Metrics::INDEX_NB_PROFILABLE,
);

public static function getMappingFromIdToName()
Expand Down
26 changes: 26 additions & 0 deletions core/Plugin/Report.php
Expand Up @@ -15,6 +15,7 @@
use Piwik\DataTable;
use Piwik\DataTable\Filter\Sort;
use Piwik\Metrics;
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
use Piwik\ViewDataTable\Factory as ViewDataTableFactory;
Expand Down Expand Up @@ -231,11 +232,23 @@ protected function init()
* might depend on a setting (such as Ecommerce) of a site. In such a case you can perform any checks and then
* return `true` or `false`. If your report is only available to users having super user access you can do the
* following: `return Piwik::hasUserSuperUserAccess();`
*
* Classes that override this method must make sure to call the parent version as well.
*
* @return bool
* @api
*/
public function isEnabled()
{
if ($this->isRequiresProfilableData()
|| (isset($this->dimension) && $this->dimension->isRequiresProfilableData())
) {
$isProfilable = Request::isCurrentPeriodProfilable();
if (!$isProfilable) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

fyi haven't looked too much through the code yet and not tested yet but I would assume this will be responsible to remove certain reports from the reporting UI page when the data is not profilable? I suppose when changing the date the reports won't change since we wouldn't reload the available reports. to be checked. just thought I leave the comment here while I have it on my mind.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll test this, it's been a while so I can't remember if this is something I tested or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually if we don't remove reports/segments but disable them some other way, this changes a lot, so I'll wait for an answer there.

Copy link
Member

Choose a reason for hiding this comment

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

@mattab any thoughts? For reports I would say we always show them and simply show a message why a report doesn't show any data (because not profilable).

For segments I think @mattab wanted segments to be removed (or someone else). But they may still be needed for historical data etc. Or if sometimes you have profilable data and sometimes not (we used to have this case on matomo org but might be bit edge case)

Copy link
Member Author

Choose a reason for hiding this comment

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

Segments are removed in the UI but nowhere else. We can also disable them and provide a tooltip saying why it doesn't make sense to use them on the current period. But when creating the segment, the period is arbitrary (eg, maybe they want it to be applied to a period w/ profilable data). Seems odd to see it greyed out and realize you have to change the period to be able to use it.

Perhaps it would be better to detect when a segment in use (ie, in the segment= query parameter) isn't going to provide correct data because the current period is not profilable, and display a notification.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mattab can you provide an answer/opinion on ^?

Copy link
Member

Choose a reason for hiding this comment

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

For reports I would say we always show them and simply show a message why a report doesn't show any data (because not profilable).

Yes, this would be the desired solution, it's less likely to break things and will also reduce any possible confusion.

Copy link
Member

@mattab mattab Aug 27, 2021

Choose a reason for hiding this comment

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

After doing more testing, i noticed sometimes they're removed and sometimes they have a footer message. I reckon that when >= 99% of all visits are not profilable, then we could directly hide all the reports. It makes the UI a lot cleaner. But if it causes difficulties, then it's fine to show all reports and have a visible warning notification in the footer?

Copy link
Member Author

Choose a reason for hiding this comment

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

showing all reports but when there's no profilable data for the selected period, there is a footer message saying so

}
}

return true;
}

Expand Down Expand Up @@ -996,6 +1009,19 @@ public function getProcessedMetricsById()
return $result;
}

/**
* Returns `true` if this report requires visit data that is profilable (that is to say, visit data that accurately
* identifies visitors across visits, which generally requires using cookies or tracking user IDs). If a report requires
* this, and Matomo finds that existing data is not good enough, the reports will not be shown, since they will not be
* accurate.
*
* @api
*/
public function isRequiresProfilableData()
{
return false;
}

/**
* Returns the Metrics that are displayed by a DataTable of a certain Report type.
*
Expand Down
26 changes: 26 additions & 0 deletions core/Plugin/Segment.php
Expand Up @@ -64,6 +64,8 @@ class Segment
*/
private $requiresRegisteredUser = false;

private $requiresProfilableData = false;

/**
* @ignore
*/
Expand Down Expand Up @@ -377,6 +379,8 @@ public function toArray()
$segment['suggestedValuesApi'] = $this->suggestedValuesApi;
}

$segment['requiresProfilableData'] = $this->requiresProfilableData;

return $segment;
}

Expand Down Expand Up @@ -436,4 +440,26 @@ private function check()
throw new Exception(sprintf('The segment %s contains a union segment to itself', $this->name));
}
}

/**
* Returns true if this segment is only useful with profilable data, false if not.
*
* @return bool
*/
public function isRequiresProfilableData(): bool
{
return $this->requiresProfilableData;
}

/**
* Set whether this segment is only useful with profilable data. If a segment requires
* profilable data and Matomo detects that this data is not present, the segment will be
* hidden in the UI. (It will still work in the API.)
*
* @param bool $requiresProfilableData
*/
public function setRequiresProfilableData(bool $requiresProfilableData): void
{
$this->requiresProfilableData = $requiresProfilableData;
}
}