site-kit-wp: Refactor filtering of `(not set)` values in reports for compatibility with Data API updates
Feature Description
From a recent notice about upcoming changes to the Data API
The Google Analytics Data API is changing the way empty fields are treated in reports.
Today, for fields where Google Analytics doesn’t receive any data, the value (not set) is returned in a report. The Google Analytics Data API will return blank values instead of (not set), beginning in March 2025.
Action Required:
Google Analytics Data API users that are pulling reporting data with filters comparing against the (not set) value will need to update their filtering conditions to compare against a blank value using the EmptyFilter filter type. If you don’t take action, your reports may show incorrect or empty results.
Note that there are two additional issues to cover the full extent of the required changes: https://github.com/google/site-kit-wp/issues/10177 and https://github.com/google/site-kit-wp/issues/10143.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- All reports that deal with empty values should be updated for compatibility with the changes outlined above
- Reports that filter/exclude empty values should use the new filter expression
Implementation Brief
Note: Refer to this POC for the changes required.
-
Install
cweagans/composer-patchespackage via composer. -
Add the patch as can be seen in POC inside
patchesdirectory. -
Add the
"patches"underextrasection in composer.json file. If needed, adjust the description."patches": { "google/apiclient-services": { "Fixes for empty filter": "patches/google-api-client-services.diff" } -
In
includes/Modules/Analytics_4/Report/RequestHelpers.php, add the additional condition foremptyFilterfilter type. -
Update the
dimensionFiltersfor the report as shown in POC forassets/js/modules/analytics-4/components/widgets/PopularAuthorsWidget.js. Similarly, update thedimensionFiltersin following files.
| File | Field Name |
|---|---|
| assets/js/modules/analytics-4/components/widgets/TopCategoriesWidget.js | customEvent:googlesitekit_post_categories |
| assets/js/modules/analytics-4/components/widgets/TopCitiesDrivingAddToCartWidget.js | city |
| assets/js/modules/analytics-4/components/widgets/TopCitiesDrivingLeadsWidget.js | city |
| assets/js/modules/analytics-4/components/widgets/TopCitiesDrivingPurchasesWidget.js | city |
- In
assets/js/modules/analytics-4/datastore/custom-dimensions-gathering-data.js, remove this condition as we no longer would be getting (not set) in report.
- Update
getDataAvailabilityReportOptionsselector such that it usesdimensionFilterswith the passed custom dimension with the same options as passed in POC, and reducelimitto1.
Test Coverage
- Fix the failing JS tests.
- Fix failing VRTs.
- Remove the
(not set)from following files as it won’t be returned.
- assets/js/modules/analytics-4/utils/data-mock.js
- assets/js/modules/analytics-4/utils/fixtures/mocked-pivot-report-3-dimensions.json
- assets/js/modules/analytics-4/utils/fixtures/mocked-pivot-report-3-dimensions.json
QA Brief
-
We need to compare the data we get for Key Metrics and Audience Segmentation reports in
mainbranch vsdevelopbranch, so as to make sure that the changes are filtering the blank values and(not set)values correctly. For this setup two test site one with main and other with develop branch. Setup the site using oi.ie site so that we have enough data to view. -
Activate the Site Kit plugin and setup Key Metrics widgets with following metrics.
- Most popular authors by pageviews
- Top categories by pageviews
- Top cities driving add to cart
- Top cities driving leads
- Top cities driving purchases
- Most popular content by pageviews
- Notice that for the
main, authors and some other widgets shall show the(not set)values. However; for thedevelopthere should be no blank or(not set)values for these metrics.
QA:Eng
- Activate the Site Kit plugin and setup Key Metrics widgets with the following metrics.
- Most popular authors by pageviews
- Top categories by pageviews
- Go to Site Kit dashboard and clear all reports in session storage. Reload the dashboard and you shall see following requests in Network tab in browser (chrome).
- Request to report endpoint with dimension
customEvent:googlesitekit_post_categoriesand filterTypeemptyFilter. - Request to report endpoint with dimension
customEvent:googlesitekit_post_authorand filterTypeemptyFilter.
Please see attached screenshot.
- Setup the
mitmproxyorproxymanas stated in project engineering workflow doc.
- clear all reports in session storage.
- Refresh the SK dashboard.
- For domain
analyticsdata.googleapis.com, ensure that there are requests sent to Analytics Data API with above mentioned custom dimensions andemptyFilterfilter expression. Please refer to below screenshot.
Changelog entry
- Refactor filtering of
(not set)values in reports to use the newEmptyFilterfilter type.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15
This is back with @ankitrox to tweak the QAB as discussed on Slack.
Once updated this will be ready for an engineer to perform the QA:Eng validation, as we’ve hit the limit of what we can realistically check at this moment in regular QA testing.
@eugene-manuilov we looked through the Google PHP API Client Services source code and it doesn’t look as simple as that, unfortunately.
Incidentally - the class to add
setEmptyFilter()/getEmptyFilter()to would beFilternotFilterExpression.Note how the class names for the various classes are captured in the models/collections, e.g. here, here, and here. This appears to be how the base class knows how to instantiate/serialize them. If we simply provide our own extended version of one of these classes, the rest of the heirarchy won’t be able to use it as the captured class name will refer to the existing version.
Thank you @techanvil for adding the comment about our discussion and preferred approach we have discussed. I will spend some time to work on monkey patch approach and will draft the details in IB.
Thanks @ankitrox, just adding a note to capture the direction here. As discussed on Slack, we are planning on taking the initial approach of monkey-patching our installed
google/apiclient-servicespackage to add support forEmptyFilter, as we’ve identified this as the most pragmatic way to provide support for the feature in the short term.Longer term we intend to generate our own version of the package, at which point we can revert the monkey-patching.