Skip to content

Fix advanced data breakdowns state when switching Analytics properties#12924

Merged
tofumatt merged 15 commits into
developfrom
bug/12892-advanced-data-breakdowns-property-switch
Jun 19, 2026
Merged

Fix advanced data breakdowns state when switching Analytics properties#12924
tofumatt merged 15 commits into
developfrom
bug/12892-advanced-data-breakdowns-property-switch

Conversation

@shervElmi

@shervElmi shervElmi commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses issue:

Relevant technical choices

  • Implementation follows the IB without deviations.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🤖 This comment is automatically updated by CI workflows. Each section is managed independently.

🎭 Playwright reports for b9a506b:

📚 Storybook for b9a506b:

  • Storybook has been deleted.

📦 Build files for b9a506b:

  • Build files have been deleted.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the Advanced Data Breakdowns settings in the Analytics 4 module to store a per-property map of enabled flags instead of a single global flag, allowing each GA4 property to maintain its own state. It introduces a new GET:custom-dimensions datapoint to fetch custom dimensions for any property and updates the JS datastore, React components, and PHP settings classes accordingly. The review feedback is highly constructive and focuses on improving robustness and security. Key recommendations include adding defensive checks for failed custom dimension requests, validating and sanitizing GA4 property IDs in both JS and PHP to prevent malformed keys, and avoiding fragile magic property access with wp_list_pluck on Google API Client model objects.

Comment thread assets/js/modules/analytics-4/datastore/custom-dimensions.js Outdated
Comment thread assets/js/modules/analytics-4/datastore/advanced-data-breakdowns.ts
Comment thread includes/Modules/Analytics_4/Advanced_Data_Breakdowns_Settings.php
Comment thread includes/Modules/Analytics_4/Datapoints/Get_Custom_Dimensions.php Outdated
shervElmi added 11 commits June 18, 2026 19:10
Change the setting from a single `enabled` flag to a map of property ID
to boolean, so each Analytics property keeps its own state. Default to
an empty map, sanitize every value to a boolean, return the stored
property IDs as the view-only keys, take a property ID in
`is_enabled()`, and merge with `array_replace` to keep the numeric keys.
Validate that every value in the `settings` map is a boolean, then pass
the whole map to `merge`, so saving one property keeps the others.
The GET datapoint returns the stored option, now a per-property map.
Update its test to expect the map for both admin and view-only users.
Add a datapoint that lists a property's Site Kit custom dimensions from
the property ID on the request, so the settings row can read a property
that is not yet saved. Return the `googlesitekit_`-prefixed parameter
names, or an empty array when the property has none.
Register `GET:custom-dimensions` with the `analyticsadmin` service, next
to the sync datapoint, and assert it in the datapoint list.
Change `AdvancedDataBreakdownsSettings` to a map of property ID to
boolean. Take a property ID in `setAdvancedDataBreakdownsEnabled` and
`isAdvancedDataBreakdownsEnabled`, and validate that every value is a
boolean.
Add `getCustomDimensions` and `hasCustomDimensionsForProperty` to read
any property's custom dimensions through the new datapoint. In
`createCustomDimensions`, create the dimensions the selected property is
missing, and create nothing while a new property is being set up.
Read the selected property's state with `getPropertyID`,
`hasCustomDimensionsForProperty`, and `isAdvancedDataBreakdownsEnabled`.
Show the green check when the property has every Site Goals custom
dimension, the loading state while they resolve, and a disabled Enable
button while a new property is being set up.
Add a story for the row with a new property selected, where the Enable
button is disabled, with the Backstop reference images that snapshot it
at the small, medium, and large widths.
`createCustomDimensions` now reads `getCustomDimensions`. Seed it in the
Site Goals tests so they do not fetch the custom-dimensions endpoint.
`createCustomDimensions` now reads `getCustomDimensions`. Seed it in the
custom-dimensions hooks tests so they do not fetch the endpoint.
@shervElmi shervElmi force-pushed the bug/12892-advanced-data-breakdowns-property-switch branch from ada072a to 419abbb Compare June 18, 2026 16:12
@shervElmi shervElmi marked this pull request as ready for review June 18, 2026 16:12
Mark the custom dimensions as not yet resolved to ensure the loading
state is displayed correctly in the SettingsAdvancedDataBreakdowns
component during tests.
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 2.92 MB

ℹ️ View Unchanged
Filename Size Change
dist/assets/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css 124 B 0 B
dist/assets/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.js 0 B 0 B 🆕
dist/assets/blocks/reader-revenue-manager/block-editor-plugin/index.js 42.7 kB 0 B
dist/assets/blocks/reader-revenue-manager/common/editor-styles.css 307 B 0 B
dist/assets/blocks/reader-revenue-manager/common/editor-styles.js 0 B 0 B 🆕
dist/assets/blocks/reader-revenue-manager/contribute-with-google/index.js 5.8 kB 0 B
dist/assets/blocks/reader-revenue-manager/contribute-with-google/non-site-kit-user.js 5.01 kB 0 B
dist/assets/blocks/reader-revenue-manager/subscribe-with-google/index.js 5.81 kB 0 B
dist/assets/blocks/reader-revenue-manager/subscribe-with-google/non-site-kit-user.js 5 kB 0 B
dist/assets/blocks/sign-in-with-google/editor-styles.css 84 B 0 B
dist/assets/blocks/sign-in-with-google/editor-styles.js 0 B 0 B 🆕
dist/assets/blocks/sign-in-with-google/index.js 18.5 kB 0 B
dist/assets/css/googlesitekit-admin-css-********************.min.css 72.1 kB +16 B (+0.02%)
dist/assets/css/googlesitekit-adminbar-css-********************.min.css 12.7 kB 0 B
dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 851 B 0 B
dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 9.07 kB 0 B
dist/assets/js/146-********************.js 960 B 0 B
dist/assets/js/201-********************.js 2.85 kB 0 B
dist/assets/js/273-********************.js 52.5 kB 0 B
dist/assets/js/314-********************.js 100 kB 0 B
dist/assets/js/315-********************.js 3.08 kB 0 B
dist/assets/js/379-********************.js 3.7 kB 0 B
dist/assets/js/397-********************.js 477 kB 0 B
dist/assets/js/590-********************.js 1.88 kB 0 B
dist/assets/js/640-********************.js 2.35 kB 0 B
dist/assets/js/909-********************.js 1.01 kB 0 B
dist/assets/js/analytics-advanced-tracking-********************.js 404 B 0 B
dist/assets/js/googlesitekit-activation-********************.js 25.1 kB 0 B
dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 61.1 kB 0 B
dist/assets/js/googlesitekit-admin-pointers-tracking-********************.js 5.36 kB 0 B
dist/assets/js/googlesitekit-adminbar-********************.js 36.7 kB 0 B
dist/assets/js/googlesitekit-api-********************.js 8.04 kB 0 B
dist/assets/js/googlesitekit-block-tracking-********************.js 5.55 kB 0 B
dist/assets/js/googlesitekit-components-********************.js 6.2 kB 0 B
dist/assets/js/googlesitekit-consent-mode-********************.js 26 kB 0 B
dist/assets/js/googlesitekit-data-********************.js 1.75 kB 0 B
dist/assets/js/googlesitekit-datastore-forms-********************.js 7.2 kB 0 B
dist/assets/js/googlesitekit-datastore-location-********************.js 1.52 kB 0 B
dist/assets/js/googlesitekit-datastore-pdf-********************.js 1.2 kB 0 B
dist/assets/js/googlesitekit-datastore-site-********************.js 18.9 kB 0 B
dist/assets/js/googlesitekit-datastore-ui-********************.js 7.36 kB 0 B
dist/assets/js/googlesitekit-datastore-user-********************.js 23.3 kB 0 B
dist/assets/js/googlesitekit-entity-dashboard-********************.js 74.6 kB 0 B
dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 2.35 kB 0 B
dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 1.12 kB 0 B
dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 2.34 kB 0 B
dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 2.3 kB 0 B
dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 2.22 kB 0 B
dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 2.44 kB 0 B
dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 1.08 kB 0 B
dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 2.44 kB 0 B
dist/assets/js/googlesitekit-i18n-********************.js 4.43 kB 0 B
dist/assets/js/googlesitekit-key-metrics-setup-********************.js 55.3 kB 0 B
dist/assets/js/googlesitekit-main-dashboard-********************.js 182 kB 0 B
dist/assets/js/googlesitekit-metric-selection-********************.js 60.3 kB 0 B
dist/assets/js/googlesitekit-modules-********************.js 27.1 kB 0 B
dist/assets/js/googlesitekit-modules-ads-********************.js 47.6 kB 0 B
dist/assets/js/googlesitekit-modules-adsense-********************.js 139 kB 0 B
dist/assets/js/googlesitekit-modules-analytics-4-********************.js 215 kB +307 B (+0.14%)
dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 23.5 kB 0 B
dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 53.6 kB 0 B
dist/assets/js/googlesitekit-modules-search-console-********************.js 66.4 kB 0 B
dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 34.1 kB 0 B
dist/assets/js/googlesitekit-modules-tagmanager-********************.js 31 kB 0 B
dist/assets/js/googlesitekit-notifications-********************.js 69.1 kB 0 B
dist/assets/js/googlesitekit-polyfills-********************.js 228 B 0 B
dist/assets/js/googlesitekit-settings-********************.js 136 kB 0 B
dist/assets/js/googlesitekit-splash-********************.js 82.3 kB 0 B
dist/assets/js/googlesitekit-user-input-********************.js 53 kB 0 B
dist/assets/js/googlesitekit-vendor-********************.js 314 kB 0 B
dist/assets/js/googlesitekit-vendor-lazy-pdf-********************.js 8.46 kB 0 B
dist/assets/js/googlesitekit-widgets-********************.js 104 kB 0 B
dist/assets/js/googlesitekit-wp-dashboard-********************.js 62 kB 0 B
dist/assets/js/runtime-********************.js 1.95 kB 0 B

compressed-size-action

The "setting is loading" test rendered without waiting, so its frozen
request settled during the next test and React logged an act() warning
there. Wait for the registry in both loading tests so each one settles
inside act() and does not affect the next.
@shervElmi

Copy link
Copy Markdown
Collaborator Author

If the E2E or VRT tests fail in this PR, the failures are not caused by this PR.

@tofumatt tofumatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! I think mostly minor comments here and a few questions… only main issue is the UI of the error message and margins for the Web Data Stream name text field.

Please let me know what you think 🙂

Comment thread assets/js/modules/analytics-4/datastore/advanced-data-breakdowns.ts Outdated
Comment thread assets/js/modules/analytics-4/datastore/custom-dimensions.test.js Outdated
Comment thread assets/js/modules/analytics-4/datastore/custom-dimensions.test.js Outdated
Comment thread assets/js/modules/analytics-4/datastore/custom-dimensions.test.js
Switch `setAdvancedDataBreakdownsEnabled` to a property-to-boolean map
and update the reducer, the caller, and the datastore tests. The action
validates the keys, so the saved map only holds valid property IDs.

Add bottom margin below the web data stream name error so it no longer
crowds the toggle. Add the `--analytics` modifier to the settings story
so the row renders as it does in production. Add an error-state variant
to the Text Field story.

Name the "enabled" flag in the custom dimensions tests, add whitespace
between the steps, and use a double-quoted view-only assertion message.
@shervElmi shervElmi force-pushed the bug/12892-advanced-data-breakdowns-property-switch branch from 393157b to 86b19b7 Compare June 19, 2026 14:06

@tofumatt tofumatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Awesome, looks great, thanks! 👍🏻

Comment on lines +78 to +90
<TextField
className="mdc-text-field--error"
label="With Error"
name="textfield"
value="https://www.sitekitbygoogle.com"
helperText="This is the error message."
trailingIcon={
<span className="googlesitekit-text-field-icon--error">
<WarningIcon width={ 14 } height={ 12 } />
</span>
}
outlined
/>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We use this pattern in four places in Site Kit, and it's kinda awkward/verbose/error-prone:

Image

Even labelling it "helper text" is a bit disingenuous, as it's really an error message.

Normally I'd say we update the API of this component while we're here adding more instances, but instead I've created a follow-up issue for this: #12935

@tofumatt tofumatt merged commit dfde01b into develop Jun 19, 2026
41 of 43 checks passed
@tofumatt tofumatt deleted the bug/12892-advanced-data-breakdowns-property-switch branch June 19, 2026 16:19
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.

2 participants