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

display info notice about channel attribution to goals reports when the current period is not profilable #19766

Draft
wants to merge 17 commits into
base: 4.x-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions config/environment/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,6 @@
)),

'test.vars.forceCliMultiViaCurl' => false,

'tests.isProfilableCheckDisabled' => true,
);
45 changes: 45 additions & 0 deletions core/API/DataTablePostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
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\Plugins\CoreHome\Columns\Metrics\EvolutionMetric;
use Piwik\Plugins\VisitsSummary\MajorityProfilable;
use Piwik\Site;

/**
* Processes DataTables that should be served through Piwik's APIs. This processing handles
Expand Down Expand Up @@ -133,11 +138,51 @@ 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)
{
if (Common::getRequestVar('disable_profilable_check', 0, 'int', $this->request) == 1) {
return $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;
}

$dateString = $period->getDateStart()->toString();
if ($period->getLabel() == 'range') {
$dateString .= ',' . $period->getDateEnd()->toString();
}

$majorityProfilable = new MajorityProfilable();
if ($majorityProfilable->isPeriodMajorityProfilable($site->getId(), $period->getLabel(), $dateString, $segment)) {
return;
}

$metricsToRemove = $majorityProfilable->getMetricsToRemoveifNotProfilable();

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

return $dataTable;
}

private function convertSegmentValueToSegment(DataTableInterface $dataTable)
{
$dataTable->filter('AddSegmentBySegmentValue', array($this->report));
Expand Down
2 changes: 1 addition & 1 deletion core/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,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
Original file line number Diff line number Diff line change
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
7 changes: 4 additions & 3 deletions core/DataAccess/ArchiveWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,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 @@ -255,7 +255,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
3 changes: 2 additions & 1 deletion core/DataAccess/LogAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private function createTemporaryTable($unprefixedSegmentTableName, $segmentSelec
return;
}

$insertIntoStatement = 'INSERT IGNORE INTO ' . $table . ' (idvisit) ' . $segmentSelectSql;
$insertIntoStatement = 'INSERT INTO ' . $table . ' (idvisit) ' . $segmentSelectSql;
$readerDb->query($insertIntoStatement, $segmentSelectBind);

$transactionLevel->restorePreviousStatus();
Expand Down Expand Up @@ -416,6 +416,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
Original file line number Diff line number Diff line change
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
7 changes: 6 additions & 1 deletion core/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 @@ -122,6 +123,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 @@ -191,6 +193,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 Expand Up @@ -368,6 +371,7 @@ public static function getDefaultMetricTranslations()
'entry_bounce_count' => 'General_ColumnBounces',
'exit_bounce_count' => 'General_ColumnBounces',
'exit_rate' => 'General_ColumnExitRate',
'nb_profilable' => 'General_ProfilableVisits',
);

$dailySum = ' (' . Piwik::translate('General_DailySum') . ')';
Expand Down Expand Up @@ -491,7 +495,8 @@ public static function getDefaultMetricsDocumentation()
'conversion_rate' => 'General_ColumnConversionRateDocumentation',
'avg_time_on_page' => 'General_ColumnAverageTimeOnPageDocumentation',
'nb_hits' => 'General_ColumnPageviewsDocumentation',
'exit_rate' => 'General_ColumnExitRateDocumentation'
'exit_rate' => 'General_ColumnExitRateDocumentation',
'nb_profilable' => 'General_ColumnProfilableVisitsDocumentation',
);

/**
Expand Down
35 changes: 34 additions & 1 deletion core/Plugin/Visualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
use Piwik\Log;
use Piwik\Metrics\Formatter\Html as HtmlFormatter;
use Piwik\NoAccessException;
use Piwik\Notification;
use Piwik\Option;
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Plugins\API\API as ApiApi;
use Piwik\Plugins\API\Filter\DataComparisonFilter;
use Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor;
use Piwik\Plugins\PrivacyManager\PrivacyManager;
use Piwik\Plugins\VisitsSummary\MajorityProfilable;
use Piwik\SettingsPiwik;
use Piwik\View;
use Piwik\ViewDataTable\Manager as ViewDataTableManager;
Expand Down Expand Up @@ -146,6 +148,8 @@
*/
class Visualization extends ViewDataTable
{
const NO_PROFILABLE_DATA_FOR_SEGMENT_NOTIFICATION_ID = 'no_profilable_data_for_segment';

/**
* The Twig template file to use when rendering, eg, `"@MyPlugin/_myVisualization.twig"`.
*
Expand Down Expand Up @@ -214,6 +218,10 @@ public function render()
$view = new View("@CoreHome/_dataTable");
$view->assign($this->templateVars);

$view->notifications = $this->config->notifications;

$this->showNotificationIfCurrentPeriodHasNoProfilableData($view);

if (!empty($loadingError)) {
$view->error = $loadingError;
}
Expand Down Expand Up @@ -248,7 +256,6 @@ public function render()
$view->reportLastUpdatedMessage = $this->reportLastUpdatedMessage;
$view->footerIcons = $this->config->footer_icons;
$view->isWidget = Common::getRequestVar('widget', 0, 'int');
$view->notifications = [];
$view->isComparing = $this->isComparing();

if (!$this->supportsComparison()
Expand Down Expand Up @@ -904,4 +911,30 @@ public function buildApiRequestArray()

return $request;
}

private function showNotificationIfCurrentPeriodHasNoProfilableData(View $view)
{
$majorityProfilable = new MajorityProfilable();
if ($majorityProfilable->isPeriodMajorityProfilable(null, null, null, '')) {
return;
}

$date = $this->requestConfig->getRequestParam('date');
$period = $this->requestConfig->getRequestParam('period');
$periodObj = Period\Factory::build($period, $date);
$periodStr = $periodObj->getPrettyString();

// no profilable data so display information explaining why unique visitors is not displayed
$notificationView = new View("@CoreHome/_nonProfilableDataWarning.twig");
$notificationView->periodStr = $periodStr;

$notification = new Notification($notificationView->render());
$notification->priority = Notification::PRIORITY_HIGH;
$notification->context = Notification::CONTEXT_INFO;
$notification->flags = Notification::FLAG_CLEAR;
$notification->type = Notification::TYPE_TRANSIENT;
$notification->raw = true;

$view->notifications[self::NO_PROFILABLE_DATA_FOR_SEGMENT_NOTIFICATION_ID] = $notification;
}
}
17 changes: 15 additions & 2 deletions core/ViewDataTable/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
use Piwik\DataTable;
use Piwik\DataTable\Filter\PivotByDimension;
use Piwik\Metrics;
use Piwik\Notification;
use Piwik\Period\PeriodValidator;
use Piwik\Piwik;
use Piwik\Plugins\API\API;
use Piwik\Plugin\ReportsProvider;
use Piwik\Plugins\VisitsSummary\MajorityProfilable;

/**
* Contains base display properties for {@link Piwik\Plugin\ViewDataTable}s. Manipulating these
Expand Down Expand Up @@ -567,6 +569,14 @@ class Config
*/
public $controllerAction;

/**
* Notifications at the top of the page to display when the visualization loads.
*
* @var Notification[]
*/
public $notifications;


/**
* Constructor.
*/
Expand Down Expand Up @@ -683,11 +693,14 @@ public function getProperties()
*/
public function setDefaultColumnsToDisplay($columns, $hasNbVisits, $hasNbUniqVisitors)
{
$majorityProfilable = new MajorityProfilable();
$isProfilable = $majorityProfilable->isPeriodMajorityProfilable(null, null, null, '');

if ($hasNbVisits || $hasNbUniqVisitors) {
$columnsToDisplay = array('label');
$columnsToDisplay = ['label'];

// if unique visitors data is available, show it, otherwise just visits
if ($hasNbUniqVisitors) {
if ($hasNbUniqVisitors && $isProfilable) {
$columnsToDisplay[] = 'nb_uniq_visitors';
} else {
$columnsToDisplay[] = 'nb_visits';
Expand Down
6 changes: 5 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,11 @@
"YourChangesHaveBeenSaved": "Your changes have been saved.",
"YourSessionHasExpired": "Your session has expired due to inactivity. Please log in to continue.",
"Update": "Update",
"Create": "Create"
"Create": "Create",
"ProfilableVisits": "Profilable Visits",
"ColumnProfilableVisitsDocumentation": "The total number of visits that we can confidently attribute to a specific visitor, because they were tracked with information that requires a user's consent.",
"NonProfilableDataTitle": "Data for this period is not Profilable",
"NonProfilableDataMessage1": "Most of the data recorded for the selected period and measurable is not profilable, meaning Matomo cannot accurately track visitors across multiple visits. Because of this the unique visitor count is not available in reports for this period. To learn more about why you're seeing this message %1$sread our documentation.%2$s"
},
"Mobile": {
"AboutPiwikMobile": "About Matomo Mobile",
Expand Down