feat: unify GTM/GA4 fields into the generic tracking-integration field - #284
Conversation
…ation list
Replaces the two dedicated "Google Tag Manager ID" / "GA4 Measurement ID"
settings fields with the same generic "Add a tracking ID or code integration"
field already used for Clientify/Brevo/ChatGPT Ads, so gtm/ga4 become
first-class entries of cookie_notice_tracking_integrations instead of
separate option keys.
- Register 'gtm'/'ga4' in CookieNotice::TRACKING_TYPES and teach
detect_tracking_snippet() to recognize a bare GTM-XXXXXXX/G-XXXXXXXXXX id
or either tool's own install snippet.
- Settings: render one generic field/list instead of two dedicated inputs,
keep the Google Site Kit conflict notice (now filtering entries out of the
shared list) and the GTM4WP double-load warning (now reading the id from
that list).
- Add a one-time admin_init migration (Settings::migrate_legacy_gtm_ga4_tracking_ids())
that moves any existing legacy gtm_id/ga4_id option values into the shared
list and clears the legacy keys, guarded by the legacy values themselves.
- get_config_callback() now sources gtmId/ga4Id from the shared list and
excludes them from the generic trackingIntegrations payload, so the
existing JS dispatch mechanism (frontblocks-cookie-notice.js and the
inline bootstrap script) needed no changes.
- The generic list's sanitizer re-validates any gtm/ga4 record against the
same GTM-/G- regexes as a defensive backstop.
Array shape ({type, id}) is unchanged, keeping frontblocks-pro's own
consumption of cookie_notice_tracking_integrations compatible.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0ec9b64e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| add_action( 'admin_menu', array( $this, 'register_menu' ) ); | ||
| add_action( 'admin_init', array( $this, 'register_settings' ) ); | ||
| add_action( 'admin_init', array( $this, 'migrate_legacy_gtm_ga4_tracking_ids' ) ); |
There was a problem hiding this comment.
Run the migration before registering the sanitizer
For every upgraded site with a legacy GTM/GA4 ID, this callback runs after register_settings() at the same admin_init priority, so update_option() inside the migration is passed through sanitize_settings(). Normal admin and AJAX requests lack the settings-form nonce and therefore return the unchanged option; even during a settings POST, the sanitizer ignores the directly populated integrations array. Consequently the legacy IDs are never migrated, while get_config_callback() now reads only the shared list, disabling existing GTM/GA4 tracking until users manually re-enter their IDs.
Useful? React with 👍 / 👎.
Pure reorder of the Cookie Notice settings screen, no logic change.
Summary
gtm/ga4as native types inCookieNotice::TRACKING_TYPESand extenddetect_tracking_snippet()to recognize a bare ID or a pasted GTM/gtag install snippet for both.admin_initmigration that moves any existingcookie_notice_gtm_id/cookie_notice_ga4_idvalues into the sharedcookie_notice_tracking_integrationslist and clears the legacy keys.get_config_callback()) at the shared list while keeping the existinggtmId/ga4Idresponse keys and the Google Site Kit / GTM4WP conflict-detection UX unchanged.{type, id}) compatible with frontblocks-pro, which already reads this shared field.Test plan
composer lintcomposer phpstancomposer test(404/404 passing)node --test tests/js/cookie-notice-injection.test.js(5/5 passing)GTM-XXXXXXXID and a full GTM snippet, confirm both detect as Google Tag Manager and the script loads only after consent🤖 Generated with Claude Code