Implement GA4 PropertySelect component in JS
There should be a GA4 version of the existing UA PropertySelect component, which covers the same functionality for GA4 properties.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- There should be a new GA4
PropertySelectcomponent inassets/js/modules/analytics-4/components/common/PropertySelect.jswhich at a high level does the same that the existing Analytics (UA)PropertySelectcomponent does, just for GA4 properties instead.- It should rely on the
modules/analytics-4datastore:- to list all GA4 properties for the currently selected account
- to select a GA4 property in the datastore when the user changes the selection
- It should visually look similar, and it should display the property ID after the property name in parentheses (e.g. "My Property (12345678)" (see related #3164 which does this in the UA
PropertySelectcomponent). - It should show a loading state in the similar conditions the existing component does.
- It should also send the same tracking event on property change.
- Other than the existing component, it should not deal with an existing tag for now, i.e. ignore that part.
- It should rely on the
- There should be Storybook coverage for the new component.
Implementation Brief
- Create file
assets/js/modules/analytics-4/components/common/PropertySelect.jswhich exports thePropertySelectfunctional component. - The component should take most of the code from
assets/js/modules/analytics/components/common/PropertySelect.jswith the following changes:- It should query the
modules/analytics-4data store instead ofmodules/analytics. - Disregard all references to
hasExistingTagwhich is not in scope for now.
- It should query the
- Add stories for the newly added
PropertySelectcomponent inassets/js/modules/analytics-4/components/common/PropertySelect.stories.js.
Test Coverage
- Add tests for the
PropertySelectcomponent.
Visual Regression Changes
- N/A
QA Brief
Note: this component isn't currently rendered anywhere except in storybook, so the ACs will need to be verified from looking at the code, tests and story.
- Verify that the ACs above have been met.
- There should be a story file at
(see: https://github.com/google/site-kit-wp/pull/3221#discussion_r629584884)assets/js/modules/analytics-4/components/common/PropertySelect.stories.jsstories/module-analytics-4.stories.js. - There should be test coverage for the new component.
Changelog entry
- N/A
IB ✅
Hi @asvinb / @tofumatt I haven’t dealt with GA4 yet, so I just had a couple of questions around this:
The component should take most of the code from assets/js/modules/analytics/components/common/PropertySelect.js with the following changes:
- It should query the modules/analytics-4 data store instead of modules/analytics.
The analytics PropertySelect component you mention uses the analytics store's getAccountID selector:
https://github.com/google/site-kit-wp/blob/11b7cff0245e1eae5e3d2ffb085cdb0fceabeef5/assets/js/modules/analytics/components/common/PropertySelect.js#L44
This selector doesn’t appear in the GA4 store. Will GA4 use the same account ID as current analytics, i.e. can I just do select( MODULES_ANALYTICS ).getAccountID()?
Also, do we need this GTM stuff? https://github.com/google/site-kit-wp/blob/11b7cff0245e1eae5e3d2ffb085cdb0fceabeef5/assets/js/modules/analytics/components/common/PropertySelect.js#L58
@johnPhillips Just saw this, so chiming in here:
This selector doesn’t appear in the GA4 store. Will GA4 use the same account ID as current analytics, i.e. can I just do
select( MODULES_ANALYTICS ).getAccountID()?
Exactly, the accounts are the same between both modules, so you can use that.
Also, do we need this GTM stuff?
No this can be ignored for the GA4 version.
Perfect, thanks @felixarntz
@felixarntz I've got a question regarding storybook coverage (and general use of this component).
The current analytics PropertySelect doesn't have its own story per se, but exists in two stories as part of the account / property / profile settings flow:
- No account selected - the
PropertySelectcomponent is disabled until an account is selected. - All selected - here, an account has been selected and all the properties associated with that account are in the
PropertySelectdropdown.
So the current PropertySelect component behaviour is that it is is disabled until an account is selected. This behaviour is also reflected in its unit tests. I'll go ahead and replicate this in the GA4 component.
However, I'm wondering whether the existing AccountSelect will be used with the new GA4 PropertySelect in the same way. If so, will we need to refactor the AccountSelect behaviour so that when an account ID is chosen, it will also look for GA4 properties that use that account ID?
I'm guessing this is a bit beyond the scope of this issue, so for now shall I just create a simple story with only the GA4 PropertySelect component?
@johnPhillips Yes, disabling the dropdown until an account is selected makes sense.
Regarding the other points, yes let's not touch AccountSelect at this point and only have a story for the GA4 PropertySelect. The GA4 properties which are shown need to be based on the current accountID (from the modules/analytics store), that is the only connection there should be for now.
QA ✅
Originally the QA brief mentioned the wrong file, but after tracking down https://github.com/google/site-kit-wp/pull/3221#discussion_r629584884 I saw it was changed without updating the brief… so I updated it here 🙂