google / google/site-kit-wp

Site Goals asks Analytics for its breakdown dimensions before they exist

Open
#13,299 0 comments 0 reactions 0 assignees View on GitHub
P2 Team S Type: Bug
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Bug Description

On every Site Kit dashboard load, the Site Goals widgets ask Analytics for the two custom dimensions their breakdown needs, `googlesitekit_event_provider` and `googlesitekit_form_id`. Site Kit creates those two dimensions on the connected Analytics property when the user clicks **Get breakdown** in the Site Goals widget. Until that click, no property has them. Analytics rejects both reports with a `400` and prints two errors to the console:

```
Field customEvent:googlesitekit_event_provider is not a valid dimension
Field customEvent:googlesitekit_form_id is not a valid dimension
```

The `useSiteGoalsBreakdown` hook should wait until `isAdvancedDataBreakdownsEnabled()` reads true for the connected property before it asks for either dimension.

## Steps to reproduce

1. Open the Site Kit dashboard with the browser console open, on a site where nobody has clicked the Get breakdown button in the Site goals section.
2. Scroll to the Site goals section.
3. Read the console: two errors name the custom dimensions `googlesitekit_event_provider` and `googlesitekit_form_id`. The network tab shows the two Analytics `report` calls that ask for those dimensions answering `400`.

Expected: the Site Goals widgets send no report for either dimension until somebody clicks Get breakdown, and the console stays clean.

## Screenshots

Image

Image

## Additional Context

- Plugin Version: 1.185.0
- Browser: Chrome

---------------

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

## Acceptance criteria

* Each Site Goals widget requests its breakdown reports only when the connected Analytics property already has that widget's breakdown custom dimension:
* The **Online store performance** widget needs `googlesitekit_event_provider`.
* The **Lead generation performance** widget needs `googlesitekit_form_id`.
* Clicking **Get breakdown** still loads the breakdown into the widget, with no page reload.
* A view-only user with Analytics shared gets the same result as an administrator.

## Implementation Brief

* [ ] Update `assets/js/modules/analytics-4/components/site-goals/hooks/useSiteGoalsBreakdown.tsx`
* Return `undefined` from the `breakdownValues` selector callback until [`hasCustomDimensions( breakdownDimension )`](https://github.com/google/site-kit-wp/blob/68f36b1394fbb504213e21fb0b04223c39a9f2b3/assets/js/modules/analytics-4/datastore/custom-dimensions.js#L480-L505) reads `true`.

### Test Coverage

* Extend `assets/js/modules/analytics-4/components/site-goals/hooks/useSiteGoalsBreakdown.test.tsx` to cover the dimension check:
* A Site Goals widget shows no breakdown tabs, and Site Kit requests no breakdown report, while the connected property holds no dimension for that widget's goal type.
* A Site Goals widget shows its breakdown tabs when the connected property holds that widget's goal type dimension.
* The Lead generation performance widget shows its tabs after the connected property gains the form dimension, with no page reload.
* Update the existing cases to state which dimensions the connected property holds.
* Extend `tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php` to cover the shared setting:
* A view-only user reads `availableCustomDimensions`.

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Research direction

Start in assets/js/modules/analytics-4/components/site-goals/hooks/useSiteGoalsBreakdown.tsx and compare its selector with hasCustomDimensions in assets/js/modules/analytics-4/datastore/custom-dimensions.js. Extend useSiteGoalsBreakdown.test.tsx for properties with and without each dimension, then update tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php for view-only access. Done means reports and tabs wait for the matching dimension, Get breakdown still loads without a reload, and shared users read availableCustomDimensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.