Skip to content

Commit 790e842

Browse files
committed
Update compliance check for ecomm restricted / text
1 parent 9c8e524 commit 790e842

File tree

8 files changed

+186
-51
lines changed

8 files changed

+186
-51
lines changed

plugins/Ecommerce/Settings/EcommerceRestricted.php

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Piwik\Piwik;
1313
use Piwik\Plugins\PrivacyManager\Settings\CompliancePolicyEnforcedSetting;
1414
use Piwik\Policy\CnilPolicy;
15+
use Piwik\Site;
16+
use Piwik\Url;
1517

1618
class EcommerceRestricted extends CompliancePolicyEnforcedSetting
1719
{
@@ -22,7 +24,47 @@ public static function getTitle(): string
2224

2325
public static function getComplianceRequirementNote(?int $idSite = null): string
2426
{
25-
return Piwik::translate('Ecommerce_EcommercePolicySettingRequirementNote');
27+
$idSites = self::getIdSitesToCheck($idSite);
28+
29+
if (!self::hasEcommerceEnabledSite($idSites)) {
30+
return self::getCompliantMessage($idSite, $idSites);
31+
}
32+
33+
if (self::getInstance($idSite)->getValue() === false) {
34+
return Piwik::translate('Ecommerce_EcommercePolicySettingNonCompliantNote');
35+
}
36+
37+
$manageUrl = 'index.php' . Url::getCurrentQueryStringWithParametersModified(self::getManageParams($idSite));
38+
39+
return Piwik::translate('Ecommerce_EcommercePolicySettingRequirementNote', ['<a href="' . $manageUrl . '">', '</a>']);
40+
}
41+
42+
private static function getManageParams(?int $idSite): array
43+
{
44+
$params = [
45+
'module' => 'SitesManager',
46+
'action' => 'index',
47+
];
48+
49+
if ($idSite !== null) {
50+
$params['idSite'] = $idSite;
51+
}
52+
53+
return $params;
54+
}
55+
56+
public static function isCompliant(string $policy, ?int $idSite = null): bool
57+
{
58+
$policyValues = static::getPolicyRequirements();
59+
if (!array_key_exists($policy, $policyValues)) {
60+
return true;
61+
}
62+
63+
$currentValue = self::getInstance($idSite)->getValue();
64+
65+
$idSites = self::getIdSitesToCheck($idSite);
66+
67+
return $currentValue === $policyValues[$policy] || !self::hasEcommerceEnabledSite($idSites);
2668
}
2769

2870
public static function getPolicyRequirements(): array
@@ -31,4 +73,35 @@ public static function getPolicyRequirements(): array
3173
CnilPolicy::class => true,
3274
];
3375
}
76+
77+
private static function getIdSitesToCheck(?int $idSite): array
78+
{
79+
if ($idSite === null) {
80+
return Site::getIdSitesFromIdSitesString('all');
81+
}
82+
83+
$ids = Site::getIdSitesFromIdSitesString((string) $idSite);
84+
85+
return empty($ids) ? [$idSite] : $ids;
86+
}
87+
88+
private static function hasEcommerceEnabledSite(array $idSites): bool
89+
{
90+
foreach ($idSites as $siteId) {
91+
if (Site::isEcommerceEnabledFor((int) $siteId)) {
92+
return true;
93+
}
94+
}
95+
96+
return false;
97+
}
98+
99+
private static function getCompliantMessage(?int $idSite, array $idSites): string
100+
{
101+
if ($idSite !== null && count($idSites) === 1) {
102+
return Piwik::translate('Ecommerce_EcommercePolicySettingCompliantSingle');
103+
}
104+
105+
return Piwik::translate('Ecommerce_EcommercePolicySettingCompliantAll');
106+
}
34107
}

plugins/Ecommerce/lang/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
"EcommerceOverviewSubcategoryHelp1": "The Ecommerce Overview section is the best place to get a high-level view of your online store’s performance. At a glance, you can see how many sales you’re making, how much revenue you are generating, and your website’s conversion rate.",
2424
"EcommerceOverviewSubcategoryHelp2": "Click on an individual metric within the sparkline chart to focus on it within the full-sized evolution graph.",
2525
"EcommerceOverviewSubcategoryHelp3": "Learn more in our Ecommerce guide here.",
26-
"EcommercePolicySettingRequirementNote": "Ecommerce must be disabled",
26+
"EcommercePolicySettingRequirementNote": "Ecommerce analytics is enabled, but specific segments are disabled (Order ID, Order revenue, Product price, Product name, Product SKU). If you prefer, you can completely disable Ecommerce tracking %1$shere%2$s.",
2727
"EcommercePolicySettingTitle": "Ecommerce Restricted",
28+
"EcommercePolicySettingCompliantSingle": "Compliant because ecommerce isn't active for this measurable.",
29+
"EcommercePolicySettingCompliantAll": "Compliant because ecommerce isn't active for any sites.",
30+
"EcommercePolicySettingNonCompliantNote": "Non compliant because ecommerce analytics is enabled unrestricted.",
2831
"SalesSubcategoryHelp1": "This section contains an extensive collection of reports to help you analyse the different conditions that most commonly lead to sales, such as the traffic and campaign sources, user time and location and devices used to access them.",
2932
"SalesSubcategoryHelp2": "You can also learn exactly how revenue is associated with each dimension, such as specific traffic types or tracked campaigns.",
3033
"EcommerceLogSubcategoryHelp1": "The Ecommerce log provides granular session-level data so you can look at the full session for each user that either made a purchase or abandoned their cart. This can help you understand what users do before and after purchasing to reveal optimisation opportunities.",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
namespace Piwik\Plugins\Ecommerce\tests\Integration;
11+
12+
use Piwik\Policy\CnilPolicy;
13+
use Piwik\Plugins\Ecommerce\Settings\EcommerceRestricted;
14+
use Piwik\Tests\Framework\Fixture;
15+
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
16+
17+
class EcommerceRestrictedTest extends IntegrationTestCase
18+
{
19+
private $ecommerceSite;
20+
private $nonEcommerceSite;
21+
22+
public function setUp(): void
23+
{
24+
parent::setUp();
25+
26+
Fixture::createSuperUser();
27+
$this->ecommerceSite = Fixture::createWebsite('2024-01-01 00:00:00', $ecommerce = 1);
28+
$this->nonEcommerceSite = Fixture::createWebsite('2024-01-02 00:00:00', $ecommerce = 0);
29+
}
30+
31+
public function tearDown(): void
32+
{
33+
CnilPolicy::setActiveStatus(null, false);
34+
parent::tearDown();
35+
}
36+
37+
public function testReturnsCompliantMessageWhenEcommerceDisabled(): void
38+
{
39+
$note = EcommerceRestricted::getComplianceRequirementNote($this->nonEcommerceSite);
40+
41+
$this->assertEquals('Ecommerce_EcommercePolicySettingCompliantSingle', $note);
42+
}
43+
44+
public function testReturnsNonCompliantMessageWhenPolicyNotEnforced(): void
45+
{
46+
CnilPolicy::setActiveStatus(null, false);
47+
$note = EcommerceRestricted::getComplianceRequirementNote($this->ecommerceSite);
48+
49+
$this->assertEquals('Ecommerce_EcommercePolicySettingNonCompliantNote', $note);
50+
}
51+
52+
public function testReturnsRequirementNoteWithLinkWhenPolicyEnforced(): void
53+
{
54+
CnilPolicy::setActiveStatus(null, true);
55+
$_GET = [];
56+
57+
$note = EcommerceRestricted::getComplianceRequirementNote($this->ecommerceSite);
58+
59+
$this->assertEquals('Ecommerce_EcommercePolicySettingRequirementNote', $note);
60+
}
61+
62+
public function testIsCompliantWhenEcommerceDisabled(): void
63+
{
64+
CnilPolicy::setActiveStatus(null, true);
65+
66+
$this->assertTrue(
67+
EcommerceRestricted::isCompliant(CnilPolicy::class, $this->nonEcommerceSite)
68+
);
69+
}
70+
71+
public function testIsCompliantWhenEcommerceEnabledAndPolicyEnforced(): void
72+
{
73+
CnilPolicy::setActiveStatus(null, true);
74+
75+
$this->assertTrue(
76+
EcommerceRestricted::isCompliant(CnilPolicy::class, $this->ecommerceSite)
77+
);
78+
}
79+
80+
public function testIsCompliantWhenEcommerceEnabledAndPolicyNotEnforced(): void
81+
{
82+
CnilPolicy::setActiveStatus(null, false);
83+
84+
$this->assertFalse(
85+
EcommerceRestricted::isCompliant(CnilPolicy::class, $this->ecommerceSite)
86+
);
87+
}
88+
}

plugins/PrivacyManager/stylesheets/compliance.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
line-height: 1.5rem;
1111
padding-left: 0.5rem;
1212
padding-right: 0.5rem;
13+
white-space: nowrap;
1314

1415
&.compliant {
1516
color: #5D9E52;

plugins/PrivacyManager/tests/System/expected/test___PrivacyManager.getComplianceStatus.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
<complianceModeEnforced>0</complianceModeEnforced>
44
<complianceConfigControlled>0</complianceConfigControlled>
55
<complianceRequirements>
6-
<row>
7-
<name>Ecommerce</name>
8-
<value>non_compliant</value>
9-
<notes>Ecommerce must be disabled</notes>
10-
</row>
116
<row>
127
<name>Device model detection disabled</name>
138
<value>non_compliant</value>
@@ -18,6 +13,11 @@
1813
<value>non_compliant</value>
1914
<notes>Only major OS and browser versions are stored.</notes>
2015
</row>
16+
<row>
17+
<name>Ecommerce Restricted</name>
18+
<value>non_compliant</value>
19+
<notes>Non compliant because ecommerce analytics is enabled unrestricted.</notes>
20+
</row>
2121
<row>
2222
<name>Turn off visits log and visitor profiles</name>
2323
<value>non_compliant</value>
@@ -65,7 +65,7 @@
6565
</row>
6666
<row>
6767
<name>Third party cookies</name>
68-
<value>compliant</value>
68+
<value>non_compliant</value>
6969
<notes>Third party cookies must be disabled</notes>
7070
</row>
7171
<row>

plugins/PrivacyManager/tests/System/expected/test_configControlledDisabled__PrivacyManager.getComplianceStatus.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
<complianceModeEnforced>0</complianceModeEnforced>
44
<complianceConfigControlled>1</complianceConfigControlled>
55
<complianceRequirements>
6-
<row>
7-
<name>Ecommerce</name>
8-
<value>non_compliant</value>
9-
<notes>Ecommerce must be disabled</notes>
10-
</row>
116
<row>
127
<name>Device model detection disabled</name>
138
<value>non_compliant</value>
@@ -18,6 +13,11 @@
1813
<value>non_compliant</value>
1914
<notes>Only major OS and browser versions are stored.</notes>
2015
</row>
16+
<row>
17+
<name>Ecommerce Restricted</name>
18+
<value>non_compliant</value>
19+
<notes>Non compliant because ecommerce analytics is enabled unrestricted.</notes>
20+
</row>
2121
<row>
2222
<name>Turn off visits log and visitor profiles</name>
2323
<value>non_compliant</value>
@@ -65,7 +65,7 @@
6565
</row>
6666
<row>
6767
<name>Third party cookies</name>
68-
<value>compliant</value>
68+
<value>non_compliant</value>
6969
<notes>Third party cookies must be disabled</notes>
7070
</row>
7171
<row>

plugins/PrivacyManager/tests/System/expected/test_configControlledEnabled__PrivacyManager.getComplianceStatus.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
<complianceModeEnforced>1</complianceModeEnforced>
44
<complianceConfigControlled>1</complianceConfigControlled>
55
<complianceRequirements>
6-
<row>
7-
<name>Ecommerce</name>
8-
<value>compliant</value>
9-
<notes>Ecommerce must be disabled</notes>
10-
</row>
116
<row>
127
<name>Device model detection disabled</name>
138
<value>compliant</value>
@@ -18,6 +13,11 @@
1813
<value>compliant</value>
1914
<notes>Only major OS and browser versions are stored.</notes>
2015
</row>
16+
<row>
17+
<name>Ecommerce Restricted</name>
18+
<value>compliant</value>
19+
<notes>Ecommerce analytics is enabled, but specific segments are disabled (Order ID, Order revenue, Product price, Product name, Product SKU). If you prefer, you can completely disable Ecommerce tracking &lt;a href=&quot;index.php?module=SitesManager&amp;action=index&amp;idSite=1&quot;&gt;here&lt;/a&gt;.</notes>
20+
</row>
2121
<row>
2222
<name>Turn off visits log and visitor profiles</name>
2323
<value>compliant</value>

tests/PHPUnit/System/expected/test_ApiTest_compliancePolicyEnforced__API.getSegmentsMetadata.xml

Lines changed: 2 additions & 32 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)