Skip to content

feat: unify GTM/GA4 fields into the generic tracking-integration field - #284

Merged
davidperezgar merged 2 commits into
trunkfrom
feat/generic-tracking-integration-field
Sep 4, 2026
Merged

feat: unify GTM/GA4 fields into the generic tracking-integration field#284
davidperezgar merged 2 commits into
trunkfrom
feat/generic-tracking-integration-field

Conversation

@davidperezgar

@davidperezgar davidperezgar commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace the two dedicated "Google Tag Manager ID" / "GA4 Measurement ID" settings fields with the existing generic "Add a tracking ID or code integration" field, so GTM and GA4 are detected and stored the same way as Clientify/Brevo/OpenAI Ads.
  • Register gtm/ga4 as native types in CookieNotice::TRACKING_TYPES and extend detect_tracking_snippet() to recognize a bare ID or a pasted GTM/gtag install snippet for both.
  • Add a one-time admin_init migration that moves any existing cookie_notice_gtm_id / cookie_notice_ga4_id values into the shared cookie_notice_tracking_integrations list and clears the legacy keys.
  • Re-point frontend script injection (get_config_callback()) at the shared list while keeping the existing gtmId/ga4Id response keys and the Google Site Kit / GTM4WP conflict-detection UX unchanged.
  • Keep the stored array shape ({type, id}) compatible with frontblocks-pro, which already reads this shared field.

Test plan

  • composer lint
  • composer phpstan
  • composer test (404/404 passing)
  • node --test tests/js/cookie-notice-injection.test.js (5/5 passing)
  • Manual check in wp-admin: paste a GTM-XXXXXXX ID and a full GTM snippet, confirm both detect as Google Tag Manager and the script loads only after consent
  • Manual check: verify migration from pre-existing GTM/GA4 values on an upgrade

🤖 Generated with Claude Code

Open WordPress Playground Preview

…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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T08:06:53.667711Z 25d2bec New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.
@davidperezgar
davidperezgar merged commit cd002b7 into trunk Sep 4, 2026
7 checks passed
@davidperezgar
davidperezgar deleted the feat/generic-tracking-integration-field branch September 4, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant