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 settings #8176
Comments
@hussain-t, I think the default value should be the one selected by the primary admin (module owner), right? See the design doc:
|
@eugene-manuilov @hussain-t actually, per-user settings are fine here. For one thing this setting was not intended to follow the primary admin's. More importantly to be aware of though, is we're actually removing this primary/secondary user settings aspect altogether due to complications with that approach. Instead, we are going to take the approach where each user's settings are initialised according to some logic and don't attempt to follow a root setting at all (see this comment thread on the design doc). I will be updating the design doc soon, apologies for the confusion in the meantime! |
Ok, thanks, @techanvil. So the default value should be neither For example, if I am the first one who selects to show the feature, then my user settings will be updated as well as the Analytics settings, right? But then, if I decide to turn it off, then it will be turned off only for me and all other users will continue seeing it, right? So, to turn it off for all users, everyone will need to go to the settings and manually turn it off for themselves? |
@eugene-manuilov, I think the default value should be site-kit-wp/includes/Core/Key_Metrics/Key_Metrics_Settings.php Lines 48 to 53 in c173f6c
This KM setting already works in the same way - each (admin) user controls their own setting, there's no way to toggle it for all users. There is admittedly a bit of a functionality gap for view-only users - both for Audience Segmentation, and for KM as it stands. I have raised this with Mariya in a thread on the design doc. Seeing as KM already works like this I suspect we'll continue as specced for the most part, but it might be worth waiting for her thoughts on this before we finalise the AC here. |
Update: Due to ongoing changes to the design doc, we may well want to expand the scope of this issue to include the additional Let's hold off until this additional thread on the design doc is also resolved. |
Update: With Evan having approved the changes, and Mariya already having given her general approval for the direction (so really just needing to sign off on the details), it's clear we will be including Therefore, I have updated the datastore configuration in the design doc, and updated the Feature Description for this issue accordingly. @hussain-t, please note that the definition for Although there are still a few last details to approve in the threads linked in the previous two comments, I think we can now safely proceed with this issue as specified. |
Thanks, @techanvil 👍 |
Thanks, @hussain-t and @techanvil. AC ✔️ |
@hussain-t, as discussed on Slack the AC does need a small tweak:
I've assigned this back to you in AC for an update. |
Thanks, @techanvil. I have updated the AC to retrieve the current value of the |
Thanks @hussain-t, the AC LGTM ✅ Assigning to you in IB as requested. Remember, we don't literally have to directly fetch the value from |
IB ✔️ |
…ce-settings Enhance/#8176 - Add REST and datastore APIs for audience settings
QA Update ✅
Action: setConfiguredAudiences( audienceResourceNames: Array ) Action: setAudienceSegmentationWidgetHidden( isWidgetHidden: boolean ) Action: saveAudienceSettings() Changed boolean value from true to false - Change settings - SELECTORS Selector: getAudienceSettings(): Object Selector: getConfiguredAudiences(): Array Selector: isAudienceSegmentationWidgetHidden(): boolean Selector: haveConfiguredAudiencesChanged(): boolean On changing the configured audiences it return the value true - |
Feature Description
Add REST and datastore APIs for audience settings. This essentially means the following REST endpoints:
GET audience-settings
POST audience-settings
And the following datastore selectors and actions (including additional Redux infra as needed):
getConfiguredAudiences()
haveConfiguredAudiencesChanged()
setConfiguredAudiences()
isAudienceSegmentationWidgetHidden()
setAudienceSegmentationWidgetHidden()
saveAudienceSettings()
See REST infrastructure and datastore configuration in the design doc.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
REST API Endpoints Implementation
GET audience-settings
endpoint in theanalytics-4
module to fetch user settings for audiences. This endpoint should return an object containing the following:configuredAudiences
: An array, with a default value ofnull
.isAudienceSegmentationWidgetHidden
: A boolean, with a default value offalse
.POST audience-settings
endpoint in theanalytics-4
module to update user settings for audiences. This endpoint should accept an object that may contain theconfiguredAudiences
array and theisAudienceSegmentationWidgetHidden
boolean value, and update the corresponding settings.Datastore Implementation
getConfiguredAudiences()
selector in theanalytics-4
partial datastore. This selector should retrieve theconfiguredAudiences
array from theGET audience-settings
endpoint.haveConfiguredAudiencesChanged()
in theanalytics-4
partial datastore to check if the local state for the configured audiences has changed.setConfiguredAudiences( audienceResourceNames )
in theanalytics-4
partial datastore to set the local state of the configured audiences.isAudienceSegmentationWidgetHidden()
selector in theanalytics-4
partial datastore. This selector should retrieve the current value of theisAudienceSegmentationWidgetHidden
setting via theGET audience-settings
endpoint.setAudienceSegmentationWidgetHidden( isWidgetHidden )
action in theanalytics-4
partial datastore. This action should update the local state of theisAudienceSegmentationWidgetHidden
setting.saveAudienceSettings()
action in theanalytics-4
partial datastore. This action should persist the local state of the audience settings via thePOST audience-settings
endpoint.Implementation Brief
REST API Endpoints
In
includes/Modules/Analytics_4
:Audience_Settings
that extendsUser_Setting
class with the following:Key_Metrics_Settings
class.OPTION
CONSTANT with the valuegooglesitekit_audience_settings
.isWidgetHidden
withisAudienceSegmentationWidgetHidden
andwidgetSlugs
withconfiguredAudiences
.In
includes/Modules/Analytics_4.php
:get_datapoint_definitions()
method within theaudienceSegmentation
feature flag enabled block:GET:audience-settings
endpoint to fetch audience user settings.POST:audience-settings
endpoint to update audience user settings.create_data_request()
method:GET:audience-settings
endpoint to fetch audience user settings.Audience_Settings::get()
method to retrieve thegooglesitekit_audience_settings
option.configuredAudiences
andisAudienceSegmentationWidgetHidden
settings.POST:audience-settings
endpoint to update the user settings for audiences.configuredAudiences
is an array andisAudienceSegmentationWidgetHidden
is a boolean.Audience_Settings::merge()
method to update thegooglesitekit_audience_settings
option.configuredAudiences
andisAudienceSegmentationWidgetHidden
settings.Fetch Stores
audience-settings.js
within theassets/js/modules/analytics-4/datastore/
directory.createFetchStore
to establish fetch stores for theGET audience-settings
andPOST audience-settings
endpoints. These stores will handle fetching and updating the audience settings from the REST API.createReducer
function from theImmer
library. It should set both theaudienceSettings.settings
andaudienceSettings.savedSettings
properties in the state.GET audience-settings
:getAudienceSettings
.configuredAudiences
andisAudienceSegmentationWidgetHidden
.POST audience-settings
:saveAudienceSettings
.configuredAudiences
is an array andisAudienceSegmentationWidgetHidden
is a boolean.Base Initial State
audienceSettings
to the initial state with the value of an empty object.audienceSettings
object will containsettings
andsavedSettings
properties.Resolvers
*getAudienceSettings()
to ensure that the audience settings are fetched from the server when the data is not already present in the state.Selectors
getAudienceSettings()
: This selector should return theaudienceSettings.settings
state.getConfiguredAudiences()
: Use thegetAudienceSettings
selector to retrieve theconfiguredAudiences
array from the audience settings.isAudienceSegmentationWidgetHidden()
: Use thegetAudienceSettings
selector to retrieve theisAudienceSegmentationWidgetHidden
setting from the audience settings.haveConfiguredAudiencesChanged()
: This selector should return the result of a comparison between thesettings
andsavedSettings
properties of theaudienceSettings
state.Actions
setConfiguredAudiences( audienceResourceNames )
: This action should locally update the list of configured audiences of theaudienceSettings.settings
state.setAudienceSegmentationWidgetHidden( isWidgetHidden )
: This action should locally update theisAudienceSegmentationWidgetHidden
setting of theaudienceSettings.settings
state.saveAudienceSettings()
: This action should call the fetch store-generatedfetchSaveAudienceSettings
action with the currentaudienceSettings.settings
state.Test Coverage
Audience_Settings
class methods.QA Brief
audienceSegmentation
feature flag is enabled.Actions
Action:
setConfiguredAudiences( audienceResourceNames: Array<string> )
Execute the action by running the following command:
Verify that the action has updated the client-side state correctly.
Run the selector to double-check:
It should return the updated array.
Action:
setAudienceSegmentationWidgetHidden( isWidgetHidden: boolean )
Execute the action by running the following command:
Verify that the action has updated the client-side state correctly.
Run the selector to double-check:
It should return the updated boolean value.
Action:
saveAudienceSettings()
Execute the action by running the following command:
Check the network tab for a
POST
request toaudience-settings
and verify that the request payload contains the correct data if the state has changed.Selectors
Selector:
getAudienceSettings(): Object
Execute the selector:
Verify that it either returns the correct object with
configuredAudiences
andisAudienceSegmentationWidgetHidden
properties or triggers a network request to fetch the audience settings.Selector:
getConfiguredAudiences(): Array<string>
Execute the selector:
Verify that it returns the array of configured audience resource names or an empty array.
Selector:
isAudienceSegmentationWidgetHidden(): boolean
Execute the selector:
Verify that it returns the boolean value of
isAudienceSegmentationWidgetHidden
.Selector:
haveConfiguredAudiencesChanged(): boolean
Execute the selector:
Verify that it returns a boolean value indicating whether the
configuredAudiences
have changed.Changelog entry
The text was updated successfully, but these errors were encountered: