Skip to content

Commit

Permalink
Merge pull request #8441 from google/bug/fix-como-region-property
Browse files Browse the repository at this point in the history
  • Loading branch information
aaemnnosttv authored Mar 28, 2024
2 parents 13c9111 + e15801b commit 1248d0c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
5 changes: 4 additions & 1 deletion includes/Core/Consent_Mode/Consent_Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ protected function render_gtag_consent_snippet() {
'ad_storage' => 'denied',
'ad_user_data' => 'denied',
'analytics_storage' => 'denied',
'regions' => $this->consent_mode_settings->get_regions(),
// TODO: The value for `region` should be retrieved from $this->consent_mode_settings->get_regions(),
// but we'll need to migrate/clean up the incorrect values that were set from the initial release.
// See https://github.com/google/site-kit-wp/issues/8444.
'region' => Regions::EU_USER_CONSENT_POLICY,
'wait_for_update' => 500, // Allow 500ms for Consent Management Platforms (CMPs) to update the consent status.
);

Expand Down
2 changes: 1 addition & 1 deletion includes/Core/Consent_Mode/Consent_Mode_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function get_type() {
protected function get_default() {
return array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
);
}

Expand Down
8 changes: 4 additions & 4 deletions includes/Core/Consent_Mode/Regions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
class Regions {

/**
* List of countries in the European Economic Area (EEA).
* List of countries that Google's EU user consent policy applies to, which are the
* countries in the European Economic Area (EEA) plus the UK.
*/
const EEA = array(
const EU_USER_CONSENT_POLICY = array(
'AT',
'BE',
'BG',
'CH',
'CY',
'CZ',
'DE',
Expand All @@ -35,6 +35,7 @@ class Regions {
'ES',
'FI',
'FR',
'GB',
'GR',
'HR',
'HU',
Expand All @@ -54,6 +55,5 @@ class Regions {
'SE',
'SI',
'SK',
'UK',
);
}
13 changes: 6 additions & 7 deletions tests/e2e/specs/front-end/consent-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ import {
wpApiFetch,
} from '../../utils';

const eeaRegions = [
const euUserConsentPolicyRegions = [
'AT',
'BE',
'BG',
'CH',
'CY',
'CZ',
'DE',
Expand All @@ -43,6 +42,7 @@ const eeaRegions = [
'ES',
'FI',
'FR',
'GB',
'GR',
'HR',
'HU',
Expand All @@ -62,7 +62,6 @@ const eeaRegions = [
'SE',
'SI',
'SK',
'UK',
];

describe( 'Consent Mode snippet', () => {
Expand Down Expand Up @@ -101,7 +100,7 @@ describe( 'Consent Mode snippet', () => {
ad_storage: 'denied',
ad_user_data: 'denied',
analytics_storage: 'denied',
regions: eeaRegions,
region: euUserConsentPolicyRegions,
wait_for_update: 500,
},
},
Expand All @@ -124,7 +123,7 @@ describe( 'Consent Mode snippet', () => {
ad_storage: 'denied',
ad_user_data: 'denied',
analytics_storage: 'denied',
regions: eeaRegions,
region: euUserConsentPolicyRegions,
wait_for_update: 500,
},
},
Expand Down Expand Up @@ -160,7 +159,7 @@ describe( 'Consent Mode snippet', () => {
ad_storage: 'denied',
ad_user_data: 'denied',
analytics_storage: 'denied',
regions: eeaRegions,
region: euUserConsentPolicyRegions,
wait_for_update: 500,
},
},
Expand All @@ -184,7 +183,7 @@ describe( 'Consent Mode snippet', () => {
ad_storage: 'denied',
ad_user_data: 'denied',
analytics_storage: 'denied',
regions: eeaRegions,
region: euUserConsentPolicyRegions,
wait_for_update: 500,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function test_get_default() {
$this->assertEqualSetsWithIndex(
array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
$default_settings
);
Expand All @@ -64,14 +64,14 @@ public function data_consent_mode_settings() {
),
array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
'enabled empty' => array(
array(),
array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
'enabled true' => array(
Expand All @@ -80,7 +80,7 @@ public function data_consent_mode_settings() {
),
array(
'enabled' => true,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
'enabled non-empty' => array(
Expand All @@ -89,7 +89,7 @@ public function data_consent_mode_settings() {
),
array(
'enabled' => true,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
'valid regions' => array(
Expand All @@ -116,7 +116,7 @@ public function data_consent_mode_settings() {
),
array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
'empty regions' => array(
Expand All @@ -125,7 +125,7 @@ public function data_consent_mode_settings() {
),
array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
'non-array regions' => array(
Expand All @@ -134,7 +134,7 @@ public function data_consent_mode_settings() {
),
array(
'enabled' => false,
'regions' => Regions::EEA,
'regions' => Regions::EU_USER_CONSENT_POLICY,
),
),
);
Expand Down Expand Up @@ -162,7 +162,7 @@ public function test_is_consent_mode_enabled() {
}

public function test_get_regions() {
$this->assertEquals( Regions::EEA, $this->settings->get_regions() );
$this->assertEquals( Regions::EU_USER_CONSENT_POLICY, $this->settings->get_regions() );

$regions = array( 'SG', 'UA-AS' );
$this->settings->set( array( 'regions' => $regions ) );
Expand Down

0 comments on commit 1248d0c

Please sign in to comment.