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 userId segment if visitor profile is disabled #21218

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins/CoreHome/Columns/UserId.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
namespace Piwik\Plugins\CoreHome\Columns;

use Piwik\Cache;
use Piwik\Columns\DimensionSegmentFactory;
use Piwik\DataTable;
use Piwik\DataTable\Map;
use Piwik\Metrics;
use Piwik\Plugin;
use Piwik\Plugin\Dimension\VisitDimension;
use Piwik\Plugins\Live\Live;
use Piwik\Segment\SegmentsList;
use Piwik\Tracker\Request;
use Piwik\Tracker\Visitor;
use Piwik\Tracker\Action;
Expand Down Expand Up @@ -45,6 +48,14 @@ public function __construct()
}
}

public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory)
{
// Configure userId segment only if visitor profile is available
if (Live::isVisitorProfileEnabled()) {
parent::configureSegments($segmentsList, $dimensionSegmentFactory);
}
}

/**
* @param Request $request
* @param Visitor $visitor
Expand Down
9 changes: 9 additions & 0 deletions plugins/Live/tests/System/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ public function testVisitorIdSegmentWithDisabledProfileForSite()
],
'testSuffix' => 'disabledProfile2'
]);

// user id segment should be disabled if visitor profile isn't available
$this->runApiTests('VisitsSummary.get', [
'idSite' => 1,
'date' => self::$fixture->dateTime,
'periods' => ['day'],
'segment' => 'userId==' . urlencode('[email protected]'),
'testSuffix' => 'disabledProfile',
]);
}

public static function getOutputPrefix()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<error message="Segment 'userId' is not a supported segment.

--&gt; To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php" />
</result>