-
Notifications
You must be signed in to change notification settings - Fork 299
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 the new Audience_Settings class and datapoints. #10153
Comments
Thanks @benbowler, this IB is looking good. A couple of small points:
|
Hey @benbowler, one more point - I've realised it would be sensible to add the REST endpoints in this issue, so the datastore additions in the subsequent #10154 can be properly tested. I've amended the AC, please can you include these in the IB and amend the estimate accordingly? We'll want to make sure we check make appropriate use of the Update: In fact, I see the title of the issue is actually defined as "Add the new Audience_Settings class and datapoints", so it looks like this just got missed from the IB. |
@benbowler, please can you expand on the |
Hey @techanvil, I've expanded the IB to handle filtering view only fields via the datapoints endpoint. Lmk your thoughts. |
Thanks @benbowler, it's an interesting idea to amend the REST route handler for datapoints, but I don't think we need to handle it at that level. I'd suggest we instead simply handle this as a one-off in the If we find that we want to provide some generic handling for these and additional settings in the future, then it would make sense to introduce a common handler, but I think it would be preferable for this to be a separate route pattern rather than adding this logic to the datapoint handler; it would be preferable not to add complexity to the datapoint route handler for a specialised subset of datapoints and rather allow these to be managed via their own route. |
Thanks for updating the IB @benbowler, that's LGTM. IB ✅ |
Hi @ankitrox, I've merged the PR for this issue, however the QAB still needs an update. As per my previous comment:
See also: #10245 (comment) Furthermore, I've noticed the brief states that Please can you update the QAB accordingly? |
Hi @techanvil , Thank you for review and merging the PR. I've updated the QAB by taking into account that only |
Thanks @ankitrox. Please note, I made a small tweak to simplify the POST payload. |
Thank you @techanvil . It looks fine now. |
QA Update: ⚠@ankitrox @techanvil admittedly, it has been a long time since I used POSTman, but here's an observation. When I run step 3, to trigger a GET request, the output is different than the QAB.
I set up Site Kit for this particular site, along with Audience Segmentation. According to the QAB Please could you check the QAB, or, let me know if this user error. Thank you. |
Thanks @wpdarren, this was a mistake in the QAB - FYI, setting up Audience Segmentation has no bearing on this particular issue because the new settings haven't been integrated into the wider codebase yet, this will be done in #8888. |
QA Update: ✅Verified:
Looks good. See screenshots below. Note. The code in the QAB has a typo in step 4. Removing the comma from the payload code and this runs perfectly in POSTman. It errored out when I left it in. |
Feature Description
Issue 1/3 to fix the bug #8888.
Add the new Audience_Settings class and datapoints, and corresponding GET/POST REST endpoints.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Audience_Settings
PHP settings class should be created.options
DB table for persistence.Modules\Analytics_4\Settings
class:availableAudiences
availableAudiencesLastSyncedAt
audienceSegmentationSetupCompletedBy
GET:audience-settings
andPOST:save-audience-settings
for fetching and updating the settings should be added to the Analytics_4 module.Implementation Brief
Extract Audience Settings to new Options Key
Note: this ticket creates the new settings store but does not yet implement it. This will be done later in #8888
Create a new settings class
includes/Modules/Analytics_4/Audience_Settings.php
, extendingCore\Storage\Setting
and implementingSetting_With_ViewOnly_Keys_Interface
, using the standard settings class pattern:OPTION
should begooglesitekit_analytics-4_audience_settings
.get_view_only_keys
should return an array containingavailableAudiences
andaudienceSegmentationSetupCompletedBy
.get_default
should return an array containing:site-kit-wp/includes/Modules/Analytics_4/Settings.php
Lines 109 to 111 in ea76d2b
get_sanitize_callback
should implement the standard pattern copying these key setting conditions:site-kit-wp/includes/Modules/Analytics_4/Settings.php
Lines 199 to 215 in ea76d2b
Update
includes/Modules/Analytics_4.php
:$audience_settings
.register
method:GET:audience-settings
datapoint.get_datapoint_definitions
method adding two new REST datapoints:GET:audience-settings
, setting'shareable' => true
.POST:save-audience-settings
create_data_request
method:GET:audience-settings
requests:current_user_can( Permissions::MANAGE_OPTIONS );
:array_intersect_key
and$audience_settings->get_view_only_keys()
to filter and return only the view only keys.POST:save-audience-settings
requests, update the value ofaudienceSegmentationSetupCompletedBy
.parse_data_response
method to parse and return the responses for each of the new endpoints.Test Coverage
includes/Modules/Analytics_4/Audience_Settings.php
class modelled on other settings tests.QA Brief
Ensure that Basic Authentication plugin is installed and activated.
Open POSTman or any similar API testing tool. Set the
Authorization
to basic auth and add username and password.Trigger a GET request to
https://example.com/wp-json/google-site-kit/v1/modules/analytics-4/data/audience-settings
, replace domain name with appropriate one. It should return following response.https://example.com/wp-json/google-site-kit/v1/modules/analytics-4/data/save-audience-settings
, replace domain name with appropriate one and add following body as JSON payload.Once successful, you shall receive the following payload.
Notice that only
audienceSegmentationSetupCompletedBy
can currently be updated as per the AC.audienceSegmentationSetupCompletedBy
set as in POST request.Changelog entry
The text was updated successfully, but these errors were encountered: