Update Google API PHP client services library to version with Idea Hub and AdSense V2 API
See original GitHub issueNow that the auto-generated PHP client code for the Idea Hub API is available, we need to upgrade the Google API services library to include it.
The main reason for the update is the above Idea Hub API - however, related to that, the new PHP client services library also includes the new AdSense API client code, which switches from the v1.4 API to the v2 API - with the v1.4 API getting deprecated in October this year. The changes are minimal, from an API perspective, only the API root differs (see https://developers.google.com/adsense/management/migrating). However, the client code appears to be generated on a slightly different foundation, so some of Site Kit’s usage of it needs to be adjusted. The changes are purely naming- and format-related though, no logic changes.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The
google/apiclient-services
PHP library incomposer.json
should be updated to^0.180
(latest version, which includes Idea Hub), and it should be updated accordingly (incomposer.lock
as well). - The list of Google services to include the PHP third-party code for in the PHP scoper config
scoper.inc.php
should be modified to includeIdeahub
. - The Google service classes for AdSense from the library now use
Adsense
instead ofAdSense
in their name, so this needs to be adjusted inscoper.inc.php
as well. - All usage of the AdSense PHP service classes also needs to be reviewed to follow the new names that the library code uses now.
Implementation Brief
- Update
composer.json
as outlined in the ACs, then runcomposer update google/apiclient-services
to actually update it. - Modify
scoper.inc.php
to addIdeahub
and replaceAdSense
withAdsense
. - Update code in
AdSense
module class to work with the new PHP library client code:- Update all library class name references from
Google_Service_AdSense
toGoogle_Service_Adsense
. - Some resources have been renamed to more precisely follow their hierarchy, e.g.
accounts_urlchannels
is nowaccounts_adclients_urlchannels
andaccounts_adunits
is nowaccounts_adclients_adunits
. This applies both for the resource property name as well as for the resource class name. - Any parent IDs that need to be specified now must no longer be passed as individiual parameters, but as a single
$parent
parameter, which works similarly to e.g. the Google Analytics 4 Admin API already does (seeAnalytics_4
class), specifying an account ID asaccounts/{accountID}
and an ad client ID asaccounts/{accountID}/adclients/{adclientID}
. - The only endpoint that includes additional changes in the request format is the one for generating a report; follow the documentation and migrate the existing arguments to be passed in that format.
- The returned objects from the API also slightly differ, for example they now no longer include the IDs as properties, but use a
name
property; so we’ll now need to also do a similar ID extraction in theAdSense
module class that is already present in theAnalytics_4
class, adding the IDs in underscore-prefixed extra properties (e.g._accountID
on an account object).
- Update all library class name references from
- Update all references to IDs and other values in objects returned from the AdSense API (most commonly change
id
to_id
andname
todisplayName
) to refer to the now manually added, underscore-prefixed ID properties. - Review all AdSense Storybook components to ensure they still receive the correct data and continue to work.
- Complete and merge #3548.
Test Coverage
- N/A
Visual Regression Changes
- N/A
QA Brief
- Test the AdSense module thoroughly, basically to ensure it still works as expected (since this issue switched all the codebase around AdSense to its new v2 API). For example covering:
- the AdSense setup flow, with different scenarios in the account
- To mock certain account and site states, you will need to use version 1.6.0 of the tester plugin which has been updated to work with AdSense API v2 (i.e. this PR and Site Kit itself once this PR is merged). That version will be published shortly (you should see an update prompt in your WP site with it by Wednesday, June 16).
- Mocking data should only be used to test all different states. Some basic testing for the AdSense setup should also be done using a real AdSense account (i.e. without the tester plugin).
- the AdSense widgets in the dashboard (test with real AdSense data, i.e. without the tester plugin)
- the AdSense module screen
- the AdSense setup flow, with different scenarios in the account
Changelog entry
- Update API client library and AdSense integration to use the new version 2 of their API.
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (9 by maintainers)
@aaemnnosttv @felixarntz I have gone through QA tasks on the PR and data loads as expected. Please assign this to me when it’s in
main
and I’ll give it another run through.@eclarke1 @fhollis @aaemnnosttv I’ve made quite some progress with the PR - I almost wanna say it looks complete, but probably a few things will still come up from testing. I’ve moved this to Sprint 51, since it blocks various other Idea Hub issues, and I’m going to prioritize completing it. Let’s just make sure to not merge it until the upcoming release has been branched off, since this one should be around for a while before a release, to get as much natural testing as possible.