Requests for settings fail for view-only users on dashboard
See original GitHub issueBug Description
In #4815, we added conditional logic to prevent source links for widgets from displaying because we don’t know if the user will be able to follow the deep link or not due to their lack of Google authentication. This issue addressed the visual aspect of the problem but there is now a residual technical problem related to the selectors used to generate the deep link.
The SourceLink itself no longer renders in view-only contexts but the URL given to it is selected in the parent. Since view-only users do not currently have access to module settings endpoints, the settings do not get preloaded and when requested on the client (triggered by a setting selector for some data needed in a service URL), it triggers a fetch request which again fails for the same reason it was not preloaded (lack of permissions).
Steps to reproduce
- Set up dashboard sharing and share Analytics with a non-admin role
- Log in as the non-admin user that was shared with
- Go to the Site Kit dashboard
- See console error for a request to Analytics settings that failed
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The use of source links for dashboard widgets that use
getService*URLselectors should be updated such that the selector is only invoked in a non-view-only context- This should ideally be done in a consistent way without requiring inline updates in each usage.
- Module settings should not be requested in a view-only context (this should be addressed by the previous point but here for completeness)
Implementation Brief
-
Files to update:
- assets/js/modules/adsense/components/dashboard/DashboardTopEarningPagesWidget.js
- assets/js/modules/adsense/components/module/ModuleOverviewWidget/Footer.js
- assets/js/modules/analytics/components/dashboard/DashboardOverallPageMetricsWidget.js
- assets/js/modules/analytics/components/dashboard/DashboardAllTrafficWidget/index.js
- assets/js/modules/analytics/components/module/ModulePopularPagesWidget/Footer.js
- assets/js/modules/search-console/components/dashboard/DashboardPopularKeywordsWidget.js
- assets/js/modules/search-console/components/dashboard/SearchFunnelWidget/Footer.js
- Note Confirm that
DataBlock.jsandLayoutFooter.jscontain the<SourceLink>but they or their parents do not currently makegetService*URLrequests.
-
Within the files to update above, identify the
getService*URLselectors the result of which are eventually used within the<SourceLink>component. In those selectors, return null early if theuseViewOnlyhook istrue. E.g. inModuleOverviewWidget/Footer.js:const viewOnlyDashboard = useViewOnly(); const accountSiteURL = useSelect( ( select ) => { if ( viewOnlyDashboard ) { return null; } select( MODULES_ADSENSE ).getServiceReportURL( generateDateRangeArgs( dateRangeDates ) ); } ); return ( <SourceLink href={ accountSiteURL } name={ _x( 'AdSense', 'Service name', 'google-site-kit' ) } external /> );
Test Coverage
- Add tests similar to
SourceLink.test.jsfor simpler components in the files to update list above. Simple components could be those which only render the<SourceLink>component with a single or couple of selectors. E.g.assets/js/modules/analytics/components/module/ModulePopularPagesWidget/Footer.js
QA Brief
- Setup SiteKit using an admin so that all widgets on the dashboard are rendered. Verify the Source Links in the footer of each widget still links to the appropriate pages as before.
- Share all modules with a non-admin user.
- Login as the non-admin user and view the ‘View Only’ dashboard. Verify that no Source Links appear in any of the widgets as before. Verify that console errors (similar to the example below) for module settings requests have reduced (as per this comment, not all errors are resolved after implementing this issue).
Google Site Kit API Error method:GET datapoint:settings type:modules identifier:analytics error:"Sorry, you are not allowed to do that."
Changelog entry
- Prevent errors on the view-only dashboard from requesting module settings unnecessarily.
Issue Analytics
- State:
- Created a year ago
- Comments:17

Top Related StackOverflow Question
Thanks for raising those, @jimmymadon. I’ve created an issue for the
getAdSenseLinkedcall: https://github.com/google/site-kit-wp/issues/5493. ThegetViewableModulesone is no longer an issue, as theuseSelectis now short circuited in view-only mode.Thanks @mohitwp, good spot. As Jimmy’s off the rest of this week I’ve picked this up and created a followup PR to fix it.