-
Notifications
You must be signed in to change notification settings - Fork 333
Description
Feature Description
How do we map Analytics and Search Console API errors within the batch so that they can be surfaced in the Admin Settings and Email Reporting panel.
#11860 shows error notices in the frontend, we didn't correctly
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Errors from Analytics, Search Console and
AdSenseAPIs that occur during Email Report generation are logged with a category identifier and displayed as per the PUE Errors spreadsheet.- These include "permission errors" which are caused due to the user not having access to the linked properties and other "report errors" that occur when requests to the Google APIs fail for reasons other than permissions access.
- The errors should be displayed only when all three attempts have failed for all emails within a single batch.
- The errors should only be displayed for admin users within the User Settings Side Panel and within the Admin Settings for Email Reports.
Implementation Brief
Backend
- Update file
includes/Core/Email_Reporting/Email_Reporting_Data_Requests.php-
Add error category constants:
PERMISSIONS_ERROR='permissions_error'REPORT_ERROR='report_error'
-
Add
categorize_report_errors( WP_Error $error )method:- Extract HTTP status from
$error->get_error_data()['status'] - Extract reason from
$error->get_error_data()['reason'] - Return
PERMISSIONS_ERRORwhen ANY of the following conditions are met:- HTTP status is
401or403 - Reason matches any of these Google API error reasons:
unauthorized- User is not authorized to perform the requestauthError- Invalid authorization credentialsexpired- Session has expiredrequired- User must be logged inforbidden- Operation is forbiddeninsufficientPermissions- User does not have sufficient permissionsaccountDeleted- User account has been deletedaccountDisabled- User account has been disabledaccessNotConfigured- Project not configured to access API
- HTTP status is
- Return
REPORT_ERRORfor all other cases (quota limits, invalid parameters, not found, server errors, etc.)
- Extract HTTP status from
-
Update
collect_analytics_payloads():- When
is_wp_error( $payload ), callcategorize_report_errors( $payload ) - Add
category_idto the existingWP_Errordata by creating a newWP_Errorobject similar to this:
site-kit-wp/includes/Core/Email_Reporting/Email_Report_Sender.php
Lines 97 to 101 in 9e0b7c1
$send_result = new WP_Error( $send_result->get_error_code(), $send_result->get_error_message(), array_merge( $error_data, array( 'category_id' => 'sending_error' ) ) ); - When
-
Update
collect_search_console_payloads()andcollect_adsense_payloads():- When
is_wp_error( $response ), callcategorize_report_errors( $response ) - Add
category_idto the existing WP_Error data as above.
- When
-
Frontend
-
Create file
assets/js/components/settings/email-reporting/notices/error/ReportErrorNotice.js- Display when
category_idisreport_error - Title and description copy per PUE Errors spreadsheet specifications and should depend on the
module_slugpassed when the category isreport_error
- Display when
-
Create file
assets/js/components/settings/email-reporting/notices/error/PermissionsErrorNotice.js- Display when
category_idispermissions_error - Title and description copy per PUE Errors spreadsheet specifications and should depend on the
module_slugpassed when the category ispermissions_error
- Display when
-
Update file
assets/js/components/settings/email-reporting/EmailReportingErrorNotice.js- Check
category_idfrom error data - Render
PermissionsErrorNoticewhencategory_idmatchespermissions_error - Render
ReportErrorNoticewhencategory_idmatchesreport_error - Fall back to existing error handling for other error types (e.g.,
sending_error,server_error)
- Check
Test Coverage
-
Update file
tests/phpunit/integration/Core/Email_Reporting/Email_Reporting_Data_RequestsTest.php- Test
categorize_report_errorsreturnsPERMISSIONS_ERRORfor 401/403 status codes - Test
categorize_report_errorsreturnsPERMISSIONS_ERRORfor permission reasons (unauthorized,authError,insufficientPermissions, etc.) - Test
categorize_report_errorsreturnsREPORT_ERRORfor other errors (quota, rate limit, invalid params) - Test that
category_idis added to WP_Error data while preserving existing data fields
- Test
-
Add JS tests for
ReportErrorNoticeandPermissionsErrorNoticecomponents- Verify correct title and description rendering
- Test component selection logic in
EmailReportingErrorNotice
QA Brief
-
Set up email reporting with a user having a valid email address. Set the frequency to say weekly.
-
To test
permissions_errorvariant: -
Set up site kit with analytics. But now, remove permissions to the property/account for the user subscribed for the email report above. This should throw several Insufficient Permissions errors on the dashboard as usual.
-
Use the tester plugin to trigger the weekly cron task in the Email Reporting tab. Wait for about 20-30 mins for all three attempts to fail. If you want to speed this process up, wait for the cron to run at least once (about 2 mins), then verify the last batch failed once in the "Email logs" page added by the tester plugin and then go to the
wp_posts_metatable in your DB, sort by descending order ofmeta_idand change the value of_send_attemptsfrom 1 to 3. -
Now go to the Email Reports side panel and verify the error notice as per the AC.
-
To test
report_errorvariant: -
Set up site kit normally with a user having all permissions for SC/Analytics. Now trigger the cron in the tester plugin. If testing locally, switch off your wifi for 20-30 mins or follow the same instructions above to modify the
_send_attemptsrecord. -
Verify the Email Reports side panel shows the report error notice as per the AC.
Changelog entry
- Add error tracking for Site Kit modules to Email Reporting.