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.

  1. Install cweagans/composer-patches package via composer.

  2. Add the patch as can be seen in POC inside patches directory.

  3. Add the "patches" under extra section in composer.json file. If needed, adjust the description.

        "patches": {
            "google/apiclient-services": {
            "Fixes for empty filter": "patches/google-api-client-services.diff"
        }
    
  4. In includes/Modules/Analytics_4/Report/RequestHelpers.php, add the additional condition for emptyFilter filter type.

  5. Update the dimensionFilters for the report as shown in POC for assets/js/modules/analytics-4/components/widgets/PopularAuthorsWidget.js. Similarly, update the dimensionFilters in 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
  1. 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.

https://github.com/google/site-kit-wp/blob/c2f58fcf10f5686e62d509f3ac203380b4ff0de9/assets/js/modules/analytics-4/datastore/custom-dimensions-gathering-data.js#L177-L178

  • Update getDataAvailabilityReportOptions selector such that it uses dimensionFilters with the passed custom dimension with the same options as passed in POC, and reduce limit to 1.

Test Coverage

  1. Fix the failing JS tests.
  2. Fix failing VRTs.
  3. 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

  1. We need to compare the data we get for Key Metrics and Audience Segmentation reports in main branch vs develop branch, 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.

  2. 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
  1. Notice that for the main, authors and some other widgets shall show the (not set) values. However; for the develop there should be no blank or (not set) values for these metrics.

QA:Eng

  1. Activate the Site Kit plugin and setup Key Metrics widgets with the following metrics.
  • Most popular authors by pageviews
  • Top categories by pageviews
  1. 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_categories and filterType emptyFilter.
  • Request to report endpoint with dimension customEvent:googlesitekit_post_author and filterType emptyFilter.

Please see attached screenshot.

Image Image
  1. Setup the mitmproxy or proxyman as 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 and emptyFilter filter expression. Please refer to below screenshot.
Image

Changelog entry

  • Refactor filtering of (not set) values in reports to use the new EmptyFilter filter type.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15

Most upvoted comments

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.

@ankitrox @techanvil do we really need that patch? Why not to create our own FilterExpression class that will extend the Google’s one and add the empty filter? This is much easier that using a patch, isn’t it?

@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 be Filter not FilterExpression.

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-services package to add support for EmptyFilter, 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.