-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add REST and datastore APIs for audience caching #8486
Comments
Hey @nfmohit, nice work here on the IB. Two points occur to me.
|
Thank you for the kind review, @techanvil.
I think this makes sense. I have updated the IB accordingly.
I agree. I have removed this point from the IB. Please let me know if this looks good now, thank you! |
That's great, thanks for the update @nfmohit. IB LGTM! ✅ |
QA Update:
|
Hi @wpdarren. Just to confirm, did you refresh the page before running Thanks! |
QA Update: ✅@nfmohit Ah, I thought I had refreshed but just ran through the test again and that did the trick! Thank you. Verified:
|
Feature Description
Add REST and datastore APIs for audience caching.
See audience caching in the design doc.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Overview
name
:name
property from the original audience object.displayName
:displayName
property from the original audience object.description
:description
property from the original audience object.audienceType
:DEFAULT_AUDIENCE
:displayName
field can’t be updated; this field can therefore be used to identify the default audiences.SITE_KIT_AUDIENCE
:displayName
anddescription
audience fields are mutable for custom audiences. Therefore in order to identify the Site Kit-created audiences we can compare the immutablefilterClauses
field, within which we embed a descriptive identifier (see audience configuration in the design doc).USER_AUDIENCE
:audienceSlug
:all-users
:All Users
default audience. Tracking slugs for the default audiences ensures we can continue to identify them audience if their name ever changes in a future Analytics update.purchasers
:Purchasers
default audience.new-visitors
:new_visitors
value which is embedded infilterClauses
as per the description forSITE_KIT_AUDIENCE
.returning-visitors
:returning_visitors
value as above.availableAudiences
setting in the Analytics module.availableAudiencesLastSyncedAt
setting.REST API
The following REST API endpoint should be added to the Analytics module:
POST:sync-audiences
availableAudiences
setting, and return it.availableAudiencesLastSyncedAt
with the current timestamp.Datastore API
The following datastore selectors should be added to the Analytics module:
getAvailableAudiences()
availableAudiences
setting.getAvailableAudiencesLastSyncedAt()
availableAudiencesLastSyncedAt
setting.syncAvailableAudiences()
POST:sync-audiences
endpoint, and return the result.Implementation Brief
includes/Modules/Analytics_4/Settings.php
:get_default
method to include two new module settings:availableAudiences
which defaults tonull
, andavailableAudiencesLastSyncedAt
which defaults to0
.get_sanitize_callback
to include sanitization for the above new module settings:availableAudiences
, it should be verified that the value is an array, otherwise, it should be reset to its default.availableAudiencesLastSyncedAt
, it should be verified that the value is an integer, otherwise, it should be reset to its default.assets/js/modules/analytics-4/datastore/base.js
:availableAudiences
andavailableAudiencesLastSyncedAt
as setting slugs.includes/Modules/Analytics_4.php
:get_datapoint_definitions
method to include a newPOST:sync-audiences
data point if theaudienceSegmentation
feature flag is enabled. Its service should beanalyticsaudiences
.create_data_request
method to include a case forPOST:sync-audiences
. It should be a duplicate of the existingGET:audiences
case where it callsPropertiesAudiences::listPropertiesAudiences
.parse_data_response
to include a case forPOST:sync-audiences
. It should use$response->getAudiences()
to get the list of audience, and then map the audiences in a way where it returns an array of objects, with each object being an audience but mapped in a structure as described in the ACs.set_available_audiences
.audienceType
property in each object, the following logic can be used:DEFAULT_AUDIENCE
: If thedisplayName
property of the audience is eitherAll Users
orPurchasers
.SITE_KIT_AUDIENCE
: If the original audience object has afilterClauses
property, where there is agroupID
field, value for which includes the textcreated_by_googlesitekit
.USER_AUDIENCE
: If the audience is neither aDEFAULT_AUDIENCE
nor aSITE_KIT_AUDIENCE
.audienceSlug
property in each object, the following logic can be used:all-users
: If thedisplayName
property of the audience isAll Users
.purchasers
: If thedisplayName
property of the audience isPurchasers
.new-visitors
: If the original audience object has afilterClauses
property, where there is agroupId
field, value for which includes the textcreated_by_googlesitekit:new_visitors
.returning-visitors
: If the original audience object has afilterClauses
property, where there is agroupId
field, value for which includes the textcreated_by_googlesitekit:returning-visitors
.$this->get_settings()->merge()
should be used to save:availableAudiences
module setting.time()
in theavailableAudiencesLastSyncedAt
module setting.assets/js/modules/analytics-4/datastore/audiences.js
:syncAvailableAudiences
that should make an API call to the newPOST:sync-audiences
endpoint.Test Coverage:
tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php
:tests/phpunit/integration/Modules/Analytics_4Test.php
:test_sync_audiences
to verify the behaviour of the newPOST:sync-audiences
endpoint.availableAudiences
andavailableAudiencesLastSyncedAt
module settings are populated, and the audiences are returned.assets/js/modules/analytics-4/datastore/audiences.test.js
:syncAvailableAudiences
action.QA Brief
i. Follow this part in the design doc to set up "New visitors" and "Returning visitors" audiences (these are SK audiences, which will later be created by SK itself).
ii. Also, create a different audience with other random details.
Verify that the returned object includes
availableAudiences
&availableAudiencesLastSyncedAt
settings withnull
and0
default values respectively.4. Run the following in the browser console:
POST:sync-audiences
, and its response should return an array of audiences that you see in https://analytics.google.com/.audienceType
andaudienceSlug
properties are set correctly according to the ACs.availableAudiences
&availableAudiencesLastSyncedAt
have been populated correctly.Changelog entry
The text was updated successfully, but these errors were encountered: