site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Implement infrastructure to query GA4 account summaries

Open felixarntz opened this issue 5 years ago • 6 comments

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_4 module class should have a new REST datapoint GET:account-summaries.
    • It should rely on the accountSummaries.list API endpoint.
    • It should return the array of account summary objects.
  • The modules/analytics-4 datastore should get a new selector getAccountSummaries().
    • It should rely on the GET:modules/analytics-4/data/account-summaries REST datapoint to get the user's account summaries.

Implementation Brief

  • In the includes/Modules/Analytics_4.php file:
    • Add 'GET:account-summaries' => array( 'service' => 'analyticsadmin' ) to the returning array of the get_datapoint_definitions method.
    • Add a new case GET:account-summaries to the create_data_request method. 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.
  • Create the new modules/analytics-4/datastore/accounts.js file that exports the new partial datastore for GA4 accounts:
    • Create a new fetch store for the account-summaries endpoint:
      • Use getAccountSummaries base name.
      • Issue a GET request to the modules/analytics-4/data/account-summaries endpoint.
      • Set received account summaries to the accountSummaries property of the state object in the reducerCallback callback.
    • Add a new selector getAccountSummaries() to the baseSelectors object. It should return accountSummaries property of the state object.
    • Add a new resolver getAccountSummaries() to the baseResolvers object. It should call getAccountSummaries.actions.fetchGetAccountSummaries() function if getAccountSummaries() selector returns undefined.
  • Import accounts datastore in the modules/analytics-4/datastore/index.js file and add it to the combined datastore.

Test Coverage

  • Add tests for the new getAccountSummaries selector.

Visual Regression Changes

  • N/A

QA Brief

  • Check that the analytics-4 module has accounts datastore with the getAccountSummaries selector that calls modules/analytics-4/data/account-summaries endpoint.
  • Verify that in the Analytics_4 class we have a new endpoint GET:account-summaries and 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.

felixarntz avatar Apr 07 '21 00:04 felixarntz

@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.

felixarntz avatar Apr 12 '21 18:04 felixarntz

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 avatar Apr 13 '21 14:04 eugene-manuilov

@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 ✅

felixarntz avatar Apr 13 '21 21:04 felixarntz

@eugene-manuilov Any chance you could add a QA brief? 🙏

johnPhillips avatar Apr 29 '21 15:04 johnPhillips

@johnPhillips ah... yes, updated! Thanks!

eugene-manuilov avatar Apr 29 '21 17:04 eugene-manuilov

QA ✅

  • Check that the analytics-4 module has accounts datastore with the getAccountSummaries selector that calls modules/analytics-4/data/account-summaries endpoint. ✓
  • Verify that in the Analytics_4 class we have a new endpoint GET:account-summaries and it pulls account summaries using GA4 Admin API. ✓

johnPhillips avatar Apr 30 '21 13:04 johnPhillips