google / google/site-kit-wp

Console error on dashboard when only Search Console is connected

Open
#13,283 0 comments 0 reactions 0 assignees View on GitHub
Module: Analytics Module: Search Console Type: Bug
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Bug Description

When a new site is in gathering data state and Analytics is not connected there is an error consistent on the dashboard.

```
GET https://sitekit-185.instawp.co/wp-json/google-site-kit/v1/modules/analytics…5B0%5D%5Bname%5D=date&startDate=2026-06-12&endDate=2026-08-06&_locale=user 403 (Forbidden)
Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"Module must be active to request data."
```

We initially spotted it during the Setup Flow Refresh Phase 3 bug bash but no ticket was created. I feel we should fix this even though it does not impact the UI/UX. I was able to recreate this on main, entity and view only dashboard.

Update: Please check the user input screen too, as I noticed the same console error appear there. I suspect it could be related to the change we made to bring the user input screen into the setup flow when only Search Console is connected.

image.png

## Steps to reproduce

1. Create a new website and set up Site Kit without Analytics.
2. Go to the dashboard and look at the console and you will notice the error message.
3. Check that you can also see it on main, entity and view only dashboard.

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

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

## Acceptance criteria

* When only SC is connected and is in gathering data state, there should be no request triggered to analytics-4 report endpoint.

## Implementation Brief

Note: POC PR: #13343

- [ ] In `assets/js/googlesitekit/notifications/register-defaults.js`:
- The `connect-more-services-notification` entry's `checkRequirements` uses `asyncRequireAll( asyncRequire( false, requireModuleGatheringData( MODULES_ANALYTICS_4 ) ), ... )`, which unconditionally resolves `MODULES_ANALYTICS_4.isGatheringData()` even when Analytics is not connected.
- Resolving `isGatheringData()` on a disconnected module triggers the `selectDataAvailability` → `hasZeroData()` → `getReport()` chain, firing a REST API request to `analytics-4/data/report` which returns 403 "Module must be active to request data."
- Replace the `asyncRequireAll(...)` shorthand with an explicit inline async `checkRequirements` function.
- In that function: resolve modules via `resolveSelect( CORE_MODULES ).getModules()`; call `requireIsAuthenticatedUser()` first and return `false` if not authenticated; check `MODULES_SEARCH_CONSOLE.isGatheringData()` and return `false` if gathering; then check `select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ANALYTICS_4 )` and only if connected, check `MODULES_ANALYTICS_4.isGatheringData()` and return `false` if gathering.
- `requireIsAuthenticatedUser`, `asyncRequire`, `asyncRequireAll`, and `requireModuleGatheringData` imports remain — `asyncRequire`/`asyncRequireAll`/`requireModuleGatheringData` are still used by `activate-analytics-notification`.

- [ ] In `assets/js/components/key-metrics-setup/KeyMetricsSetupApp.js`:
- The `useSelect` block that reads `select( MODULES_ANALYTICS_4 ).isGatheringData()` has no guard and fires the same API call when Analytics is not connected.
- Inside that `useSelect`, call `select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ANALYTICS_4 )` directly (rather than capturing the outer `isGA4Connected` closure) to properly subscribe to `CORE_MODULES`. Only call `select( MODULES_ANALYTICS_4 ).isGatheringData()` when the module is connected.
- In the `isSyncing` selector, `!hasResolvedAnalytics4DataAvailability` is derived from `select( MODULES_ANALYTICS_4 ).hasFinishedResolution( 'isGatheringData' )`. When analytics is not connected and the resolution is never intentionally triggered, this flag stays `false` indefinitely, keeping `isSyncing` `true`. In the same way, use `select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ANALYTICS_4 )` inside `isSyncing` and short-circuit `hasResolvedAnalytics4DataAvailability` to `true` when analytics is not connected.

### Test Coverage

- Add/update a test for `connect-more-services-notification` in `register-defaults.test.js` that verifies `checkRequirements` returns `false` (and does not call `isGatheringData` for analytics) when Analytics is not connected and only Search Console is connected.
- Add/update tests for `KeyMetricsSetupApp` covering the case where `isGA4Connected` is `false`: confirm `isGatheringData` is never called on `MODULES_ANALYTICS_4`, and that `isSyncing` resolves to `false` once Search Console's `isGatheringData` resolves.
- Fix any existing tests that break due to the guarded `isGatheringData` call.

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Research direction

Start with assets/js/googlesitekit/notifications/register-defaults.js and assets/js/components/key-metrics-setup/KeyMetricsSetupApp.js, then read the related tests in register-defaults.test.js and the KeyMetricsSetupApp test file. Reproduce the Search Console-only setup and verify that no Analytics gathering-data request occurs, isSyncing settles correctly, and the focused tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.