site-kit-wp: KM metric tile report errors on view-only dashboard
Bug Description
The “Set up Banner CTA” should never be displayed for non-authenticated users, i.e. on the view-only dashboard. Furthermore, Key Metric widget tiles throw data loading errors on the view-only dashboard.
Steps to reproduce
- Login as an authenticated admin and Set up the Key Metrics widget by answering the questionnaire. Select the “Sell products or services” answer to question 1. Complete the questionnaire.
- This will display the four key metric tiles on the site: Top Performing Keywords, Top Traffic Source, Most Engaged Traffic Source, Top Performing Content
- Now use the dashboard sharing permissions modal to give other roles access to both Analytics and Search-console (i.e. editors, contributors, etc.)
- Login as one of the roles that have been given access above, say an Editor and see the set up banner CTA and errors on the dashboard for the Key Metrics Widget.
Screenshots
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- If a view-only user has shared module access (via dashboard sharing) to search console and / or analytics, then they should be able to view the Key Metric widget tiles that rely on search console and / or analytics.
Implementation Brief
There are two main aspects of this issue that require addressing in order to satisfy the AC thereof:
- Adding the necessary metrics and dimensions to the applicable
Request
classes of the affected modules. - Updating the callback permission(s) of endpoints within applicable REST controller classes affected by shared dashboard viewing of KMW’s.
- This update is required because the current permission check of
current_user_can( Permissions::AUTHENTICATE )
will fail for all non admin users in a view only dashboard environment, yet the correct response of this route is a requirement for rendering the KMW’s. - As part of this update, filtering of the
author
key within the'callback'
methods response should be undertaken as necessary based on the current users permissions.
- This update is required because the current permission check of
Add metrics and dimensions to shared metric and dimensions validation variables
- Identify the modules, metrics and dimensions being utilized by the KMW components within the applicable module folders. At the time of writing, KMW’s are included in the following modules and locations:
- The KMW’s located within the folder at
assets/js/modules/analytics-4/components/widgets
- The KMW’s located within the folder at
assets/js/modules/search-console/components/widgets
- The KMW’s located within the folder at
- Once the metrics and widgets have been identified, update the applicable PHP
Request
class within the modulesReport
namespace. - Update the
Analytics_4
module as follows:- Within the
Request
class atincludes/Modules/Analytics_4/Report/Request.php
:- Locate the
validate_shared_metrics()
method and add the necessary metrics to the array. This should be:activeUsers
sessionConversionRate
- Locate the
validate_shared_dimensions()
method and add the necessary dimensions to the array. This should be:newVsReturning
,sessionDefaultChannelGroup
,city
- Locate the
- Within the
Update REST endpoint permissions & filtering of author key from response
- In order for KMW’s to render on shared dashboard views, the permissions for the
core/user/data/user-input-settings
READABLE endpoint need to be updated to be less strict and equivalent to those found for thecore/user/data/key-metrics
endpoint located atincludes/Core/Key_Metrics/REST_Key_Metrics_Controller.php
:- Within the current
get_rest_routes()
method of theREST_User_Input_Controller
class located atincludes/Core/User_Input/REST_User_Input_Controller.php
: - Locate the
WP_REST_Server::READABLE
array entry for thecore/user/data/user-input-settings
endpoint:- Update the
'permission_callback'
key value to check that the user has one of the following capabilitiesPermissions::VIEW_SPLASH
Permissions::VIEW_DASHBOARD
- Update the
- Within the current
- Filter the response data so that the
{setting}.author
key of each answer object is omitted if the current user lacks thelist_users
capability
Test Coverage
- No changes necessary
QA Brief
- Follow the steps to reproduce.
- Once the modules are shared with the view-only users, log in to the view-only SK dashboard.
- Verify that the KM widgets appear for the shared Analytics and SC without errors.
- Remove the shared settings to either one of the modules.
- Verify only the widgets connected to the shared module appear.
- Verify there is no permissions-related console (network) errors.
- Verify that the “Most popular products by pageviews” widget links are clickable. There was an existing bug that I’ve fixed in this issue. Please refer to this comment point 2.
- Verify that the “Most popular products by pageviews” widget contents are non-interactive plain texts on the view-only dashboard. Please refer to this comment point 3.
Changelog entry
- Fix issue that caused Key Metrics Widgets in view-only dashboard to appear as unusable links or cause errors.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17
Commits related to this issue
- Merge branch 'develop' into bug/#7400-show-kmw-view-only-dashboard. — committed to google/site-kit-wp by hussain-t a year ago
- Merge branch 'develop' into bug/#7400-show-kmw-view-only-dashboard. — committed to google/site-kit-wp by hussain-t a year ago
- Merge pull request #7415 from google/bug/#7400-show-kmw-view-only-dashboard Bug/#7400 - Show KMW tiles on view-only dashboard only if the modules are shared — committed to google/site-kit-wp by tofumatt a year ago
Thanks @hussain-t for these fixes.
I’ll leave points 1 and 2 for a Code / Merge reviewer but that SGTM!
Yes - this is definitely not a bug bash blocking issue and can be dealt separately as a know issue. I can create one later today and test this once the PR has been merged. Thanks again. Nice work!
IB ✅
@jimmymadon – I removed the part about the CTA from the test coverage section since that has been moved to #7386
@wpdarren
Being fixed in #7349 - the CTA should never be displayed on the View-only dashboard.
Both of these links should appear as view only users are allowed to edit their metric selection.
Instead of creating a follow up PR before the bug-bash, I have created #7436 to fix both of the above.
The banner is hidden for view only users in #7349.
@bethanylang, I’ve fixed it as part of this issue in my PR.
@hussain-t We discussed this on stand-up today and decided it’s best to take care of this in your PR here as opposed to in a separate issue. I’ve closed #7421 (which @jimmymadon had created for this) so you can update your PR to address those non-clickable links. Thanks!
Thanks @10upsimon ! I’m going to amend this quickly to unblock it in the interest of time, but basically we should apply the author-related changes to the response in the controller rather than in the
get_answers
method. Otherwise this should be good to go 👍@aaemnnosttv Correct - the AC of #6259 states: “When the Key Metrics widget is active for any user (authenticated admin or view-only user), a “Change metrics” link should be created as show in the Figma mock.”