-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add privacy setting allowing to randomise config ID on the backend (#…
…22952) * Implement initial config ID randomisation * Initialise system test and test fixture * Put UI control behind a feature flag * Build dist files
- Loading branch information
1 parent
dfff2d0
commit 74e65ea
Showing
18 changed files
with
442 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
plugins/PrivacyManager/FeatureFlags/ConfigIdRandomisation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Piwik\Plugins\PrivacyManager\FeatureFlags; | ||
|
||
use Piwik\Plugins\FeatureFlags\FeatureFlagInterface; | ||
|
||
/** | ||
* PLEASE NOTE! | ||
* | ||
* This feature flag only controls if the Config ID randomisation setting is visible in the Privacy settings. | ||
* | ||
* Disabling the feature flag once the privacy setting was enabled won't stop the config ID randomisation unless | ||
* disabled, either through the UI with the feature flag enabled or by removing the option from the db. | ||
* | ||
*/ | ||
class ConfigIdRandomisation implements FeatureFlagInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'ConfigIdRandomisation'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
plugins/PrivacyManager/tests/Fixtures/RandomizedConfigIdVisitsFixture.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Plugins\PrivacyManager\tests\Fixtures; | ||
|
||
use Piwik\Date; | ||
use Piwik\Option; | ||
use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; | ||
use Piwik\Plugins\PrivacyManager\PrivacyManager; | ||
use Piwik\Tests\Framework\Fixture; | ||
use Piwik\Tracker\Cache; | ||
|
||
class RandomizedConfigIdVisitsFixture extends Fixture | ||
{ | ||
public static $dateTimeNormalConfig = '2015-01-01 01:00:00'; | ||
public static $dateTimeRandomizedConfig = '2015-02-01 01:00:00'; // as above + 1 month | ||
|
||
public $dateTime; | ||
public $idSite = 1; | ||
|
||
/** @var PrivacyManagerConfig */ | ||
private $privacyManagerConfig; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->dateTime = self::$dateTimeNormalConfig; | ||
|
||
Option::set(PrivacyManager::OPTION_USERID_SALT, 'simpleuseridsalt1'); | ||
Cache::clearCacheGeneral(); | ||
|
||
$this->privacyManagerConfig = new PrivacyManagerConfig(); | ||
|
||
$this->setUpWebsite(); | ||
|
||
// config off | ||
// should NOT randomize | ||
$this->trackVisits(false); | ||
|
||
// config on | ||
// should randomize | ||
$this->dateTime = self::$dateTimeRandomizedConfig; | ||
$this->trackVisits(true); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
// empty | ||
} | ||
|
||
private function setConfigIdRandomisationPrivacyConfig(bool $config) | ||
{ | ||
$this->privacyManagerConfig->randomizeConfigId = $config; | ||
} | ||
|
||
private function addHour() | ||
{ | ||
$this->dateTime = Date::factory($this->dateTime)->addPeriod(1, 'hour')->getDatetime(); | ||
} | ||
|
||
private function setUpWebsite() | ||
{ | ||
if (!self::siteCreated($this->idSite)) { | ||
$idSite = self::createWebsite($this->dateTime, $ecommerce = 1); | ||
$this->assertSame($this->idSite, $idSite); | ||
} | ||
} | ||
|
||
protected function trackStandardVisits(int $visits) | ||
{ | ||
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true); | ||
$t->setUrl('http://example.com/'); | ||
for ($v = 1; $v <= $visits; $v++) { | ||
$dt = Date::factory($this->dateTime)->addPeriod($v, 'minute')->getDatetime(); | ||
$t->setForceVisitDateTime($dt); | ||
self::checkResponse($t->doTrackPageView("Standard visit - $dt")); | ||
} | ||
} | ||
|
||
protected function trackVisitsWithMultipleActions(int $visits, int $actions) | ||
{ | ||
for ($v = 1; $v <= $visits; $v++) { | ||
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true); | ||
$t->setUrl('http://example.com/'); | ||
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addPeriod($v, 'minute')->getDatetime()); | ||
|
||
self::checkResponse($t->doTrackPageView("Visit with actions - $v")); | ||
for ($a = 1; $a <= $actions; $a++) { | ||
$dt = Date::factory($this->dateTime) | ||
->addPeriod($v, 'minute') | ||
->addPeriod($a, 'second') | ||
->getDatetime(); | ||
$t->setForceVisitDateTime($dt); | ||
self::checkResponse($t->doTrackAction("http://example.com/$dt", 'link')); | ||
} | ||
} | ||
} | ||
|
||
protected function trackVisitsWithUserId(int $visits) | ||
{ | ||
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true); | ||
$t->setUserId('foobar'); | ||
$t->setUrl('http://example.com/'); | ||
for ($v = 1; $v <= $visits; $v++) { | ||
$dt = Date::factory($this->dateTime)->addPeriod($v, 'minute')->getDatetime(); | ||
$t->setForceVisitDateTime($dt); | ||
self::checkResponse($t->doTrackPageView("Visit with user ID set - $dt")); | ||
} | ||
} | ||
|
||
protected function trackEcommerceOrder(int $orders) | ||
{ | ||
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true); | ||
$t->setUrl('http://example.com/myorder'); | ||
self::checkResponse($t->doTrackPageView('Visit with ecommerce order')); | ||
|
||
for ($o = 1; $o <= $orders; $o++) { | ||
$dt = Date::factory($this->dateTime)->addPeriod($o, 'second')->getDatetime(); | ||
$t->setForceVisitDateTime($dt); | ||
$t->doTrackEcommerceOrder('Ecommerce order ID - ' . $dt, 10 * $o, 7, 2, 1, 0); | ||
} | ||
} | ||
|
||
protected function trackVisits(bool $randomizeConfigId) | ||
{ | ||
$this->setConfigIdRandomisationPrivacyConfig($randomizeConfigId); | ||
|
||
// track visits | ||
$this->trackStandardVisits(2); | ||
$this->addHour(); | ||
|
||
// track visits with multiple actions | ||
$this->trackVisitsWithMultipleActions(3, 2); | ||
$this->addHour(); | ||
|
||
// track visits with set UserID | ||
$this->trackVisitsWithUserId(2); | ||
$this->addHour(); | ||
|
||
// track ecommerce order | ||
$this->trackEcommerceOrder(3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.