Closed felixarntz closed 2 years ago
cc @ThierryA @marrrmarrr @aaemnnosttv
IB ✅
@techanvil @tofumatt Since the metrics and dimensions are not in the IB, please make sure to encompass in the code review or QA here to double-check the codebase for whether the implementation actually includes all the necessary metrics and dimensions (and not more).
Make some requests with invalid AdSense report metrics and dimensions and verify that they return a 400 error with an error message in the format Unsupported (metric|dimension)/s requested: SOME_METRIC
@techanvil I do see the error message but it is returning a 500 error. From the QAB, it should be 400, so just checking.
Verified:
Checked that there are no errors for the AdSense report requests in the Network tab, i.e. requests with the path /wp-json/google-site-kit/v1/modules/adsense/data/report.
@wpdarren the status code changed from what was in the IB and looks like the QAB wasn't updated, but it should be a 500 in this case.
I should note that requesting dummy metrics will error in a non-shared context as well with a slightly different message ("Unknown metric(s)" I believe), so it's important to test with real metrics which are outside of the allowed metrics for SK in both shared and non-shared contexts to see that it works for the module owner but not for a shared user.
You can see all the available metrics and dimensions for AdSense here: https://developers.google.com/adsense/management/metrics-dimensions
The QAB mentions which ones are allowed in a shared context, although again, they should still work outside of a shared context. Let me know if you have any questions about this.
I am trying to find a site that I have access to live AdSense data. For some reason I am unable to see data from our usual testing site. Will pick this up on Monday and get moved forward.
Verified:
Viewing the shared dashboard
Viewing as main admin
As main admin user when viewing the dashboard, the Performance over the last X days and Top Earning Pages widgets still work as expected within Monetization. There are no errors for the AdSense report requests in the Network tab
Did a few extra checks in the context of the module owner and a view-only user. Confirmed non-allowlisted metrics and dimensions raised errors for the view-only user but not the owner, as expected 👍
Similar to #5711: As an additional security & privacy requirement, the report endpoints should only allow for specific metrics and dimensions to be requested when used by a user with shared access - namely those metrics and dimensions that are also used by Site Kit (so that users with shared access can't just craft any report request they like).
While this is still not 100% bullet proof, it is more compliant with really only sharing data that the Site Kit dashboard also shows anyway.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
AdSense
GET:report
endpoint should be adjusted as follows:metrics
anddimensions
.googlesitekit_shareable_adsense_metrics
andgooglesitekit_shareable_adsense_dimensions
.Implementation Brief
In
includes/Modules/AdSense.php
:Create a new protected method,
validate_report_metrics
.is_using_shared_credentials
(introduced in #5711) isfalse
and return early withnull
if so.getReport
selector.googlesitekit_shareable_adsense_metrics
.null
.Create a new protected method
validate_report_dimensions
.validate_report_metrics
but for dimensions instead of metrics. These could be refactored to DRY if it seems worthwhile, but it's probably not needed.In the
GET:report
case of thecreate_data_request
method:validate_report_metrics
.$metrics
.validate_report_metrics
returns an error message, return a newWP_Error
object including the error message, with codeinvalid_metrics
and HTTP status400
.validate_report_dimensions
.$dimensions
.validate_report_dimensions
returns an error message, return a newWP_Error
object including the error message, with codeinvalid_dimensions
and HTTP status400
.Test Coverage
QA Brief
/wp-json/google-site-kit/v1/modules/adsense/data/report
.400
error with an error message in the format _Unsupported (metric|dimension)/s requested: SOMEMETRICESTIMATED_EARNINGS, IMPRESSIONS, PAGE_VIEWS_CTR, PAGE_VIEWS_RPM
DATE
Be sure to test with a other real AdSense metrics and dimensions, see: https://developers.google.com/adsense/management/metrics-dimensions These should be requestable as the module owner but only the valid ones above should be requestable in a shared context.
Changelog entry