google / google/site-kit-wp

Limit API requests when the user doesn't have access to the connected entity

Open
#7,033 2 comments 0 reactions 1 assignee Assigned to @aaemnnosttv View on GitHub
Module: AdSense Module: Analytics Module: Search Console P1 Type: Enhancement Type: Support UX
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Bug Description

If a user doesn't have access to the connected Analytics account they'll encounter an [error message indicating this](https://sitekit.withgoogle.com/documentation/troubleshooting/dashboard/#insufficientpermissionsanalytics), as expected.

![image](https://github.com/google/site-kit-wp/assets/41326532/3cd4ab5e-7ced-41a1-a439-97e068f110e5)

When checking the browser console there are multiple requests made, see below.

Console errors


```
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…5B0%5D%5Bname%5D=date&startDate=2023-08-12&endDate=2023-09-08&_locale=user 403
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…etricName%5D=totalUsers&orderby%5B0%5D%5Bdesc%5D=true&limit=6&_locale=user 403
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…3-09-08&orderby%5B0%5D%5Bdimension%5D%5BdimensionName%5D=date&_locale=user 403
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…3-09-08&compareStartDate=2023-07-15&compareEndDate=2023-08-11&_locale=user 403
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/analytics-4/data/conversion-events?_locale=user 403
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…0Search&orderby%5B0%5D%5Bdimension%5D%5BdimensionName%5D=date&_locale=user 403
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
index.js:199 Google Site Kit API Error method:GET datapoint:conversion-events type:modules identifier:analytics-4 error:"The caller does not have permission"
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…rs%5BsessionDefaultChannelGrouping%5D%5B0%5D=Organic%20Search&_locale=user 403
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…0Search&orderby%5B0%5D%5Bdimension%5D%5BdimensionName%5D=date&_locale=user 403
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/analytics-4/data/property?propertyID=328495990&_locale=user 403
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
index.js:199 Google Site Kit API Error method:GET datapoint:property type:modules identifier:analytics-4 error:"The caller does not have permission"
tsp.bundle.js:1
GET https://tradeargument.s3-tastewp.com/wp-json/google-site-kit/v1/modules/ana…ame%5D=screenPageViews&orderby%5B0%5D%5Bdesc%5D=true&limit=10&_locale=user 403
index.js:199 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics-4 error:"User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id."
```

If possible limit API requests if it's known a user doesn't have access.


![image](https://github.com/google/site-kit-wp/assets/41326532/c1fc14c1-f3a5-46f7-b4c8-9c3b401ba614)

https://github.com/google/site-kit-wp/assets/41326532/6a52ee73-0311-4953-a69a-39af83b75523

The same may apply to AdSense, or even Search Console in rate occasions where one administrator removes verification from another at Search Console level (if verification was done prior to Site Kit setup, via non Site it means, ie. HTML file upload).

## Steps to reproduce

1. Set up Site Kit on a new site (with Analytics)
2. Create another WP Administrator account
3. Login to that new user account from another browser session
4. Set up Site Kit using a Google account that doesn't have access to the Analytics property connected by another administrator
5. When landing back on the SK dashboard you'll notice permissions errors as expected
6. Check the browser console for errors

## Screenshots

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

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

## Acceptance criteria

* For modules that implement reporting on the dashboard for their connected entities which require access at the Google account level, if a request for a report fails with an insufficient permissions error, any subsequent report requests for that module should be skipped until access is confirmed to be re-established
* This state should persist across page reloads but remain on the client only
* If any module with report requests being skipped, a non-dismissible alert should be displayed at the top explaining that the dashboard is in a kind of data-interrupted state (listing all affected modules), similar to the recoverable modules alert
* There should be a button to check access, which should make a single request per-module to test access to the respective module, and if successful, the block for report requests for that module should be cleared, allowing it to resume normal reporting functionality

## Implementation Brief

*

### Test Coverage

*

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.