-
Notifications
You must be signed in to change notification settings - Fork 286
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 GA4 availableCustomDimensions
module setting and relevant datastore infrastructure
#7598
Comments
To clarify, even though this issue says that it is blocked by #7114, this can still be worked on and carried forward. It's just that without #7114, this module setting won't be available for view-only users, and thus SK will not be able to make report requests for them without seeing if the custom dimensions are available via the module setting. It will still work for regular users. CC: @bethanylang |
I've assigned this to @aaemnnosttv for review as Evan had some final comments in the design doc about this section and I didn't want to hold off adding ACs here until those were resolved. |
@nfmohit the first point reads good to me, especially the detail about resetting this if the connected property changes, which is indeed important and something I hadn't considered yet 👍 The second point reads a bit closer to an IB. As far as AC is concerned, we're mainly concerned with the interfaces of selectors and actions. Additional thoughts:
We shouldn't need to add this to state separately – it should remain as part of the
This should always call the fetch action to list custom dimensions rather than use a selector. I think it should also save the updated settings. It might be simpler to implement this as a
We can also refer to these as custom dimension names since they're 1:1 with their parameters. As an aside, it might be nice to allow for using the selector with a single dimension as we'll have cases for using it in both ways. |
I have updated the ACs (and relevant parts of the design doc) accordingly, thank you @aaemnnosttv. With a new |
@nfmohit the pattern of calling the GET endpoint to list all the custom dimensions in the resolver of the selector is consistent with the approach we use during module setup, where we're configuring the state of the module before saving at the end. These datapoints usually also require the account and other IDs needed to make these requests because the module isn't connected yet. In this case, we really just want to call out to the API to update the list of dimensions we're keeping track of in module settings for the connected property. If we don't have any other need for |
I agree, thank you @aaemnnosttv. I have updated the ACs for #7573 & #7574 to remove the requirement for the datapoint and its relevant selectors. |
AC LGTM @nfmohit – some of it borders on IB territory but we do have some technical ACs sometimes so it's not a big deal. A few thoughts:
This doesn't block this from moving forward though, so I'll send back to you for any potential revisions, but aside from the above, this is ✅ |
…imensions-module-setting Enhance/#7598 - Add GA4 `availableCustomDimensions` module setting and relevant datastore infrastructure
Thanks for checking @techanvil that's good to know. I believe this is due to being passed through different parts of the config so they're not actually competing for the same parameters as I had thought. See https://support.google.com/analytics/answer/12370404?sjid=8553378467151786531-NA#zippy=%2Cgoogle-tag-websites:~:text=Use%20the%20following%20drop%2Ddowns%20to%20see%20information%20about%20how%20to%20set%20user%20properties -- This one is ready for QA again now that the follow-up PR has been merged. |
QA Update
|
@mohitwp, It appears there might be a misunderstanding. The createCustomDimensions action is designed to function without any arguments, as the QAB precisely describes.
The
Yes, this |
QA Update
|
@mohitwp, I see where the confusion is coming from. When you pass the categories as individual arguments (strings), the selector evaluates based on the first argument. Since your first dimension is valid, it returns To validate multiple dimensions together, you should pass them as an array: googlesitekit.data.select('modules/analytics-4').hasCustomDimensions( ['googlesitekit_post_author', 'googlesitekit_post_categories', 'test'] ) By using the array format, it will correctly check if all dimensions within the array are available before returning a result. |
Thanks @hussain-t ! QA Update ✅
Pass Cases -
|
@mohitwp – I see @hussain-t explained this in his previous comment so it looks like this was just accidentally copied in your last update as it seems like this was the only clarification needed from your previous pass. I double checked this and it does work as @hussain-t explained 👍 |
Thank you @aaemnnosttv ! |
Feature Description
The
analytics-4
module should have a new module setting added that will persistently store an array of custom dimensions (only parameter names, e.g.googlesitekit_post_author
) that have been created/are available for the GA property, sayavailableCustomDimensions
.The intention is to use this module setting as a reference to check whether a certain custom dimension is available from the site’s database instead of the Google service, as this is a check that would be made quite frequently by the metric tiles that depend on custom dimensions.
Besides the module setting, datastore infrastructure should also be added that will populate and retrieve this module setting.
See relevant sections in design doc:
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
newsKeyMetrics
feature flag is on.analytics-4
module that should store an array of Site Kit-specific custom dimensions that have been created/are available for the connected GA property, sayavailableCustomDimensions
.null
.null
for default/unset, or an array of strings all starting with agooglesitekit_
prefix.analytics-4
propertyID
) is changed in Site Kit, this module setting should be reset tonull
.Analytics_4
datapoints (being implemented in #7573, another datapoint should be added as follows:POST:sync-custom-dimensions
that should use theGoogleAnalyticsAdmin/Resource/PropertiesCustomDimensions::listPropertiesCustomDimensions
infrastructure to get a list of all custom dimensions and parse its response to look for custom dimensions that start with thegooglesitekit_
prefix. It should then update the newavailableCustomDimensions
analytics-4
module setting with an array of the matching custom dimension names.syncAvailableCustomDimensions
action that should interact with thePOST:sync-custom-dimensions
datapoint.getAvailableCustomDimensions
selector’s (available by default based on the module setting) resolver should be extended so that if the newavailableCustomDimensions
analytics-4
module setting isnull
and the current user has theMANAGE_OPTIONS
capability, it should dispatch thesyncAvailableCustomDimensions
action, wait for it to complete, and return the updated module setting value.hasCustomDimensions
selector that should accept a custom dimension names name (string) or an array of custom dimension names (e.g.googlesitekit_post_categories
). It should call thegetAvailableCustomDimensions
selector and check if the accepted name(s) exist in the array returned from thegetAvailableCustomDimensions
selector.createCustomDimension
action (introduced in #7574) should be removed, however, the fetch store should be persisted.createCustomDimensions
action that should do the following:CORE_USER
getKeyMetrics
selector to get a list of the currently selected key metric widget tiles.KEY_METRICS_WIDGETS
constant (inassets/js/components/KeyMetrics/key-metrics-widgets.js
at the time of writing) under a newrequiredCustomDimensions
array property.availableCustomDimensions
analytics-4
module setting to find out what required custom dimensions have not been created yet.createCustomDimension
fetch store (introduced in #7574) to create them incrementally.googlesitekit_post_date
:parameterName
:googlesitekit_post_date
displayName
:WordPress Post Creation Date
description
:Date of which this post was published
scope
:event
googlesitekit_post_author
:parameterName
:googlesitekit_post_author
displayName
:WordPress Post Author
description
:User ID of the author for this post
scope
:event
googlesitekit_post_categories
:parameterName
:googlesitekit_post_categories
displayName
:WordPress Post Categories
description
:Comma-separated list of category IDs assigned to this post
scope
:event
googlesitekit_post_type
:parameterName
:googlesitekit_post_type
displayName
:WordPress Post Type
description
:Content type for this post
scope
:event
syncAvailableCustomDimensions
action to update the list of available custom dimensions.Implementation Brief
newsKeyMetrics
feature flag is enabled:includes/Modules/Analytics_4/Settings.php
:availableCustomDimensions
having a default value ofnull
.get_sanitize_callback
method, add a new case for this setting so that only the following are accepted as values:null
googlesitekit_
prefix.includes/Modules/Analytics_4.php
:register
method, update the callback function for theupdate_option_googlesitekit_analytics-4_settings
hook such that when thepropertyID
module setting changes to a new value, theavailableCustomDimensions
module setting should be reset tonull
.get_datapoint_definitions
method, add a newPOST
datapoint calledsync-custom-dimensions
which should use theanalyticsadmin
service.create_data_request
method:POST:sync-custom-dimensions
datapoint.Google\Site_Kit_Dependencies\Google\Service\GoogleAnalyticsAdmin\Resource\PropertiesCustomDimensions::listPropertiesCustomDimensions
method passing thepropertyID
module setting to get a list of the available custom dimensions for the GA4 property.parse_data_response
method:POST:sync-custom-dimensions
datapoint.listPropertiesCustomDimensions
method response should include an array of objects for the custom dimensions available for the GA4 property.googlesitekit_
prefix in theparameterName
property and has anEVENT
scope.availableCustomDimensions
module setting with an array of matchingparameterName
(string) values, or an empty array if there are no available or matching custom dimensions.assets/js/modules/analytics-4/datastore/base.js
:availableCustomDimensions
as the module setting in the datastore.assets/js/modules/analytics-4/datastore/custom-dimensions.js
:syncAvailableCustomDimensions
that should interact with thePOST:sync-custom-dimensions
datapoint.syncAvailableCustomDimensions
that should interact with the fetch store with the same name.createModuleStore
utility would automatically provide infrastructure to retrive the value of theavailableCustomDimensions
module setting, add a resolver namedgetAvailableCustomDimensions
that should extend this default behaviour.availableCustomDimensions
module setting isnull
, the current user is authenticated and has theMANAGE_OPTIONS
capability, dispatch thesyncAvailableCustomDimensions
action to update the module setting, wait for it to complete, and return the updated module setting value.hasCustomDimensions
that should return if one or more passed custom dimensions are available for the connected GA4 property. It should accept a string as a custom dimension name, or an array of one or more custom dimension names. It should call the automatically availablegetAvailableCustomDimensions
selector, check if the accepted name(s) exist in the array returned and returntrue
if so, otherwise returnfalse
. If the selector is used to check if multiple custom dimensions are available, it should returntrue
only if ALL of them are available.createCustomDimensions
that should do the following:CORE_USER
getKeyMetrics
selector to get a list of the currently selected key metric widget tiles.KEY_METRICS_WIDGETS
constant (inassets/js/components/KeyMetrics/key-metrics-widgets.js
at the time of writing) under a newrequiredCustomDimensions
array property.availableCustomDimensions
module setting to find out what required custom dimensions have not been created yet.createCustomDimension
fetch store to create each of them.assets/js/modules/analytics-4/datastore/constants.js
so that it can be referenced in the code, stories, and tests.syncAvailableCustomDimensions
action to update the list of available custom dimensions.Test Coverage
tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php
:tests/phpunit/integration/Modules/Analytics_4Test.php
:availableCustomDimensions
module setting is reset tonull
whenpropertyID
is changed.POST:sync-custom-dimensions
datapoint.assets/js/modules/analytics-4/datastore/custom-dimensions.test.js
:syncAvailableCustomDimensions
action.getAvailableCustomDimensions
selector to verify that the extended resolver works to update theavailableCustomDimensions
module setting when it isnull
.hasCustomDimensions
selector.createCustomDimensions
action.QA Brief
newsKeyMetrics
feature flag is enabled.Least engaging pages
andPages per visit
widgets from the selection panel. For testing purposes, these widgets have the required custom dimensions.Selectors
1.
getAvailableCustomDimensions
null
), invoking this selector should trigger a network request to thesync-custom-dimensions
datapoint and update the available custom dimensions.2.
hasCustomDimensions
parameterName
property of the custom dimension object (AC) to check its availability.false
if any of the given dimensions is unavailable.Actions
1.
syncAvailableCustomDimensions
sync-custom-dimensions
datapoint.2.
createCustomDimensions
googlesitekit_post_author
andrequiredCustomDimensions
custom dimensions are not available for the GA4 property.create-custom-dimension
datapoint.sync-custom-dimensions
datapoint should be made after the custom dimensions are created.getAvailableCustomDimensions
selector.Specific Scenarios
null
in the state.getAvailableCustomDimensions
selector, ensure that the custom dimensions are fetched again if they arenull
.Changelog entry
availableCustomDimensions
module setting and relevant datastore infrastructure.The text was updated successfully, but these errors were encountered: