Implement infrastructure to query GA4 account summaries
It should be possible to query GA4 account summaries (see #3012 for related UA account summaries issue).
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The
Analytics_4module class should have a new REST datapointGET:account-summaries.- It should rely on the accountSummaries.list API endpoint.
- It should return the array of account summary objects.
- The
modules/analytics-4datastore should get a new selectorgetAccountSummaries().- It should rely on the
GET:modules/analytics-4/data/account-summariesREST datapoint to get the user's account summaries.
- It should rely on the
Implementation Brief
- In the
includes/Modules/Analytics_4.phpfile:- Add
'GET:account-summaries' => array( 'service' => 'analyticsadmin' )to the returning array of theget_datapoint_definitionsmethod. - Add a new case
GET:account-summariesto thecreate_data_requestmethod. It should call the$this->get_service( 'analyticsadmin' )->accountSummaries->listAccountSummaries( array( 'pageSize' => 200 ) )function until all account summaries are received and return the aggregated array of account summaries.
- Add
- Create the new
modules/analytics-4/datastore/accounts.jsfile that exports the new partial datastore for GA4 accounts:- Create a new fetch store for the
account-summariesendpoint:- Use
getAccountSummariesbase name. - Issue a GET request to the
modules/analytics-4/data/account-summariesendpoint. - Set received account summaries to the
accountSummariesproperty of the state object in thereducerCallbackcallback.
- Use
- Add a new selector
getAccountSummaries()to thebaseSelectorsobject. It should returnaccountSummariesproperty of the state object. - Add a new resolver
getAccountSummaries()to thebaseResolversobject. It should callgetAccountSummaries.actions.fetchGetAccountSummaries()function ifgetAccountSummaries()selector returnsundefined.
- Create a new fetch store for the
- Import accounts datastore in the
modules/analytics-4/datastore/index.jsfile and add it to the combined datastore.
Test Coverage
- Add tests for the new
getAccountSummariesselector.
Visual Regression Changes
- N/A
QA Brief
- Check that the
analytics-4module hasaccountsdatastore with thegetAccountSummariesselector that callsmodules/analytics-4/data/account-summariesendpoint. - Verify that in the
Analytics_4class we have a new endpointGET:account-summariesand it pulls account summaries using GA4 Admin API.
Changelog entry
- Add data store selector and matching REST datapoint to the GA4 module to retrieve account summaries.
@eugene-manuilov Why the pageSize limit on the PHP side? Is there a specific low default limit we need to override? It is only allowed to have 50 Analytics accounts per Google account, so this should never be more than 50 entries anyway.
It is only allowed to have 50 Analytics accounts per Google account, so this should never be more than 50 entries anyway.
:thinking: I read that there is a limit in 100 Analytics account per Google account and it can be increased in Analytics 360. Anyway the documentation says the following for the pageSize argument:
The maximum number of AccountSummary resources to return. The service may return fewer than this value, even if there are additional pages. If unspecified, at most 50 resources will be returned. The maximum value is 200; (higher values will be coerced to the maximum)
It makes me think that in theory users can have even more than 100 "summaries", so we need to be prepared :smile:
@eugene-manuilov Makes sense, let's go with that then. It would be good to add a code comment on why this is set to 200 though.
IB ✅
@eugene-manuilov Any chance you could add a QA brief? 🙏
@johnPhillips ah... yes, updated! Thanks!
QA ✅
- Check that the
analytics-4module hasaccountsdatastore with thegetAccountSummariesselector that callsmodules/analytics-4/data/account-summariesendpoint. ✓ - Verify that in the
Analytics_4class we have a new endpointGET:account-summariesand it pulls account summaries using GA4 Admin API. ✓