Cookie Consent: Add configurable geo provider#49998
Conversation
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
Code Coverage SummaryThis 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. 🤷 |
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
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.geoand nestedgeo.*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. |
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
|
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. |
Fixes WOOA7S-1600
Proposed changes
features.geoandgeo.*Cookie Consent config, with WPCOM as the default provider.geo.*keys authoritative.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
git diff --name-only origin/trunk...HEAD.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.