-
Notifications
You must be signed in to change notification settings - Fork 279
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
Remove GET:audiences endpoint and getAudiences selector #8606
Remove GET:audiences endpoint and getAudiences selector #8606
Conversation
Build files for e68de59 have been deleted. |
Size Change: +40 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
@@ -124,7 +124,7 @@ export default { | |||
|
|||
registry | |||
.dispatch( MODULES_ANALYTICS_4 ) | |||
.receiveGetAudiences( { audiences: audiencesFixture } ); | |||
.setAvailableAudiences( { audiences: audiencesFixture } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should provide an array of objects that represent the cached audiences, rather than the underlying fixtures.
I.e. they should have the shape as described in the AC for #8486 (with the exception of the "All Users" displayName
which should be mapped to "All visitors" as part of this issue).
.setAvailableAudiences( { audiences: audiencesFixture } ); | |
.setAvailableAudiences( mappedCachedAudiences ); |
Actually, further note that these calls to setAvailableAudiences()
and setConfiguredAudiences()
should be replacable by a single call to receiveGetSettings()
:
registry
.dispatch( MODULES_ANALYTICS_4 )
.receieveGetSettings( { availableAudiences, configuredAudiences } );
includes/Modules/Analytics_4.php
Outdated
$audience_item = array( | ||
'name' => $audience->getName(), | ||
'displayName' => $audience->getDisplayName(), | ||
'displayName' => ( 'All Users' === $display_name ) ? __( 'All Visitors', 'google-site-kit' ) : $display_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note the value for "All visitors" should have a lower-case initialled "visitors", and it should also not be translated (the value it's replacing is not translated and is always created in English):
'displayName' => ( 'All Users' === $display_name ) ? __( 'All Visitors', 'google-site-kit' ) : $display_name, | |
'displayName' => ( 'All Users' === $display_name ) ? 'All visitors' : $display_name, |
const audienceData = | ||
select( MODULES_ANALYTICS_4 ).getAvailableAudiences(); | ||
|
||
return Object.values( audienceData ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call to Object.value()
should no longer be needed:
const audienceData = | |
select( MODULES_ANALYTICS_4 ).getAvailableAudiences(); | |
return Object.values( audienceData ); | |
return select( MODULES_ANALYTICS_4 ).getAvailableAudiences(); |
…mentation/AudienceTiles.stories.js Co-authored-by: Tom Rees-Herdman <tom.rees-herdman@10up.com>
…mentation/AudienceTiles.js Co-authored-by: Tom Rees-Herdman <tom.rees-herdman@10up.com>
Co-authored-by: Tom Rees-Herdman <tom.rees-herdman@10up.com>
@@ -124,7 +124,7 @@ export default { | |||
|
|||
registry | |||
.dispatch( MODULES_ANALYTICS_4 ) | |||
.receiveGetAudiences( { audiences: audiencesFixture } ); | |||
.setAvailableAudiences( mappedCachedAudiences ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankitrox sorry if this suggestion was a bit unclear - it was for illustrative purposes, you'll still need to create mappedCachedAudiences
(feel free to use a different name for it too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@techanvil Thank you. I spotted this that I committed it by mistake, I changed it to audiencesFixture
which should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ankitrox - but, this still needs an update. As per my previous comment, the audience fixtures represent the audiences as returned from the GA4 API.
This is not representative of the mapped versions of the audience objects that will be cached and therefore stored in the availableAudiences
setting.
For reference here's the audiences fixture, as you can see it contains a set of Audience
resources which have the following shape:
{
"name": string,
"displayName": string,
"description": string,
"membershipDurationDays": integer,
"adsPersonalizationEnabled": boolean,
"eventTrigger": {
object ([AudienceEventTrigger](https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.audiences#AudienceEventTrigger))
},
"exclusionDurationMode": enum ([AudienceExclusionDurationMode](https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.audiences#AudienceExclusionDurationMode)),
"filterClauses": [
{
object ([AudienceFilterClause](https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.audiences#AudienceFilterClause))
}
]
}
As discussed in #8486, these should be mapped to a set of objects with the following shape which are then cached in the availableAudiences
setting:
{
"name": string,
"displayName": string,
"description": string,
"audienceType": string, // `"DEFAULT_AUDIENCE"`, `"SITE_KIT_AUDIENCE"` or `"USER_AUDIENCE"`.
"audienceSlug"`: string, // `"all-users"`, `"purchasers"`, `"new-visitors"`, `"returning-visitors"`, or an empty string.
}
So, the audiences fixture needs mapping to objects with the above shape to pass to setAvailableAudiences()
. It might be worth creating a new fixture, say available-audiences.json
, rather than mapping these in code for the tests etc.
Add support of audienceSlug to tooltip component.
"description": "Description", | ||
"displayName": "Test Audience", | ||
"audienceType": "USER_AUDIENCE", | ||
"audienceSlug": "test-users" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ankitrox just a quick heads up - please note the audienceSlug
is set to an empty string for user-defined audiences, as can be seen here:
site-kit-wp/includes/Modules/Analytics_4.php
Lines 2244 to 2245 in 109d750
// Return an empty string for user defined audiences. | |
return ''; |
"audienceSlug": "test-users" | |
"audienceSlug": "" |
{ | ||
"name": "properties/12345/audiences/1", | ||
"description": "All users", | ||
"displayName": "All Users", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankitrox, also the displayName
here should be "All visitors"
to reflect how it will be mapped as per the related change in this PR:
"displayName": "All Users", | |
"displayName": "All visitors", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ankitrox, nice work here so far.
I've left a few comments, please take a look.
Also, the QA Brief will need an update as it's currently focused on the change to createAudience()
which will be removed. This should instead reflect the change to getAvailableAudiences()
(i.e. the sync should be triggered when the value is initially null
), and it's also worth including a QAB point to give the AudienceTiles
component a quick check in Storybook to verify it's unchanged.
// Sync available audiences in the state. | ||
if ( error === undefined ) { | ||
yield fetchSyncAvailableAudiencesStore.actions.fetchSyncAvailableAudiences(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ankitrox. Sorry I didn't spot this prior to implementation - I realise this is specified in the IB, but we shouldn't really be syncing cached audiences in createAudience()
. When we initially set the feature up, we'll be creating the "new visitors" and "returning visitors" audiences via two calls to createAudience()
. It would be preferable to avoid two calls to sync the audiences at the point, rather we can dispatch the syncAvailableAudiences()
action once both createAudience()
calls have completed.
So, please can you remove this addition?
// Sync available audiences in the state. | |
if ( error === undefined ) { | |
yield fetchSyncAvailableAudiencesStore.actions.fetchSyncAvailableAudiences(); | |
} |
|
||
// If available audiences not present, sync the audience in state. | ||
if ( audiences === undefined ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the IB, this condition should explicitly test for audiences
being null
, rather than undefined
.
We generally use undefined
to indicate that a given entity hasn't loaded yet (i.e. it's not been retrieved from the backend).
So, when audiences
was being retrieved via its own API call, this test for undefined
made sense. However, now audiences
is retrieved from the availableAudiences
setting, which means the loading is handled for us via the underlying Analytics settings store.
What we want to do is to ensure that the audience cache is synced when availableAudiences
is loaded and determined to be in its default state, i.e. it's null
:
'availableAudiences' => null, |
Therefore, please can you update this condition as follows, and please also add a bit of test coverage for this aspect:
if ( audiences === undefined ) { | |
if ( audiences === null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ankitrox, thanks for making these changes.
There are just a couple of aspects that were missed from previous comments:
From #8606 (comment):
Therefore, please can you update this condition as follows, and please also add a bit of test coverage for this aspect
As per the quoted point, please can you add a bit of test coverage for the changes included via the getAvailableAudiences()
resolver? I.e. that it should sync the audiences when the setting is null
.
From #8606 (review):
Also, the QA Brief will need an update as it's currently focused on the change to
createAudience()
which will be removed. This should instead reflect the change togetAvailableAudiences()
(i.e. the sync should be triggered when the value is initiallynull
), and it's also worth including a QAB point to give theAudienceTiles
component a quick check in Storybook to verify it's unchanged.
As per the above, please can you updated the QA Brief accordingly. Thanks!
Thank you @techanvil . I have addressed following two points.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ankitrox, this LGTM!
*/ | ||
getAudiences( state ) { | ||
return state.audiences; | ||
return registry.select( MODULES_ANALYTICS_4 ).getAvailableAudiences(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@techanvil @ankitrox resolvers don't have a return value :) This line can simply be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaemnnosttv thanks for spotting that, I totally missed it at review time. I'm including a fix in my forthcoming PR for #8131.
fetchMock.postOnce( syncAvailableAudiencesEndpoint, { | ||
body: availableAudiences, | ||
status: 200, | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fetchMock here shouldn't be necessary since the expectation is for it not to be fetched. @ankitrox
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks here too, @aaemnnosttv, I am removing this call in my forthcoming PR too.
Summary
Addresses issue:
GET:audiences
endpoint and thegetAudiences()
selector, replacing usage of this withgetAvailableAudiences()
. #8487Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist