Skip to content

Cookie Consent: Add configurable geo provider#49998

Draft
chihsuan wants to merge 5 commits into
trunkfrom
auto/WOOA7S-1600
Draft

Cookie Consent: Add configurable geo provider#49998
chihsuan wants to merge 5 commits into
trunkfrom
auto/WOOA7S-1600

Conversation

@chihsuan

Copy link
Copy Markdown
Member

Fixes WOOA7S-1600

Proposed changes

  • Add nested features.geo and geo.* Cookie Consent config, with WPCOM as the default provider.
  • Allow custom geo endpoints, cookie names, cookie duration, GDPR countries, CCPA regions, and error behavior through config.
  • Keep geo resolution client-side and only add resolved geo cookies to Boost's ignored cache-cookie list when geo is enabled.
  • Preserve legacy flat geo config aliases while making explicit nested geo.* keys authoritative.
  • Document the custom geo provider contract and disabled-geo behavior.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No new tracking events or tracked properties. This changes Cookie Consent geo source configuration and region-selection behavior.

Testing instructions

  • Confirm the branch diff is scoped to Cookie Consent only: git diff --name-only origin/trunk...HEAD.
  • Run mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent test.
  • Run mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent typecheck.
  • Run mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent build.
  • Run mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent exec eslint src/modules/cookie-consent/utils.ts src/modules/cookie-consent/view.ts tests/utils.test.ts.
  • Run composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php.
  • Run composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php.
  • Run composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php.
  • Run vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar.

chihsuan added 3 commits June 26, 2026 17:03
Summary:
- Normalize cookie consent config into nested features and geo groups while
  preserving legacy top-level geo aliases for existing filters.
- Gate geo cache-cookie filtering and frontend geo config emission on
  features.geo, and update the frontend resolver to consume geo provider
  settings.
- Document the custom geo endpoint contract and add helper coverage for nested
  geo config and configured region lists.

Rationale:
- Consumers need to replace the WPCOM geo endpoint and regulated-region lists
  without forking the package.
- Keeping resolution client-side and only ignoring resolved geo cookies when geo
  is enabled preserves the existing cache-safety behavior.

Tests:
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent test
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent typecheck
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent build
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent exec eslint src/modules/cookie-consent/utils.ts src/modules/cookie-consent/view.ts tests/utils.test.ts
- composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php
- composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php
- composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php
- vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar
Summary:
- Always register the Boost ignore-cookies callback and re-check geo config
  inside the callback so late config filters are respected.
- Prefer explicit nested geo schema values over changed legacy aliases when
  both are present.
- Remove redundant geo enablement from the README custom-provider example and
  add a focused disabled-geo snippet.

Rationale:
- Runtime geo checks avoid an init-time filter ordering constraint for
  consumers that disable geo through the config filter.
- Nested geo config is the current schema, so it should not be silently
  overridden by legacy aliases during partial migrations.

Tests:
- composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php
- composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php
- composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php
- vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar
Summary:
- Treat nested geo key presence as authoritative when resolving legacy alias
  conflicts, including explicit default values.
- Use nullish fallback for the frontend geo provider and default geo lists for
  fallback parity with sibling fields.

Rationale:
- Consumers using the current nested schema should not have explicit nested
  intent overridden by older flat aliases.
- Consistent fallback semantics reduce surprises if provider values evolve.

Tests:
- composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php
- composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php
- composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php
- vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent test
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent typecheck
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent exec eslint src/modules/cookie-consent/utils.ts src/modules/cookie-consent/view.ts tests/utils.test.ts
- mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent build
@jp-launch-control

jp-launch-control Bot commented Jun 26, 2026

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the Cookie Consent package configuration schema to support a configurable geo provider (defaulting to WPCOM), including a nested features.geo flag to disable geo resolution entirely, while preserving legacy flat geo config keys via normalization.

Changes:

  • Add features.geo and nested geo.* configuration with legacy key aliasing and normalization (PHP + JS helpers).
  • Update the Interactivity store to gate geo resolution, cookie reads/writes, and region-based consent logic on features.geo.
  • Document the new config schema and custom geo provider contract; add unit tests for geo config helpers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
projects/packages/cookie-consent/tests/utils.test.ts Adds unit tests for geo config helpers and precedence rules.
projects/packages/cookie-consent/src/modules/cookie-consent/view.ts Gates geo initialization/usage on features.geo and switches to getGeoConfig()-derived settings.
projects/packages/cookie-consent/src/modules/cookie-consent/utils.ts Introduces geo config helpers and updates GDPR/CCPA matching to use normalized geo config.
projects/packages/cookie-consent/src/class-cookie-consent.php Adds normalized nested geo config (plus legacy aliases), and only ignores geo cookies in Boost cache when geo is enabled.
projects/packages/cookie-consent/README.md Documents the new config schema, custom provider contract, and disabled-geo behavior.
projects/packages/cookie-consent/changelog/add-configurable-geo-provider Adds changelog entry for configurable geo provider/settings.

Comment thread projects/packages/cookie-consent/src/class-cookie-consent.php Outdated
@chihsuan chihsuan marked this pull request as draft June 26, 2026 09:18
Normalize configured GDPR country lists to uppercase and CCPA region lists to lowercase in both PHP config normalization and frontend geo config helpers. Add JS and PHP coverage for nested geo lists and legacy aliases.

Reviewer-comment-ids: 3480368909, 3480368933
Avoid PHP 8.5 ReflectionMethod::setAccessible() deprecations in the config normalization tests and satisfy Phan's null-coalescing rule in Cookie Consent config normalization.

Review comments: 3480368909, 3480368933
@chihsuan

Copy link
Copy Markdown
Member Author

Symphony AI is treating the coverage summary as informational and made no change because it reports unavailable parent-commit coverage data rather than a requested code change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs [Package] Cookie Consent [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants