Implement dropdown component showing all UA and GA4 properties
A new Analytics component PropertySelectIncludingGA4 should be implemented in the analytics module which lists all Analytics properties the user has in the current account, of both UA and GA4 type. This component will be used in the "ga4-transitional" flow (see #3170) to list all of the account's UA and GA4 properties.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- A new component
PropertySelectIncludingGA4should be implemented withinassets/js/modules/analytics/components/common. - It should render a dropdown with similar appearance and high-level behavior as the existing
PropertySelect, with the difference that it includes all UA properties and all GA4 properties in the current account (relying on thegetPropertiesIncludingGA4selector from #3167). For example:- If no valid account ID is specified yet, the component should return
null(also see related #3243). - If properties are still loading, the component should return a loading bar.
- Every property should show up as its name with its ID in parentheses.
- If no valid account ID is specified yet, the component should return
- Since
getPropertiesIncludingGA4returns objects of different shape, this has to be catered for. Each object is either a UA property or a GA4 property, and they have their respective names and IDs in different fields (check the AnalyticsPropertySelectand the GA4PropertySelectcomponents for reference). - The currently selected property in the dropdown is determined as follows:
- If the
getPrimaryPropertyTypeselector returns "ga4", the selected property has to come from themodules/analytics-4store'sgetPropertyIDselector. - Otherwise or if the
getPrimaryPropertyTypeselector returns "ua", the selected property has to come from themodules/analyticsstore'sgetPropertyIDselector.
- If the
- When selecting a property from the dropdown, the following should happen:
- If the selected property is a GA4 property, the
setPrimaryPropertyTypeaction should be called to indicate "ga4". Then, themodules/analytics-4store'sselectPropertyaction should be used to set the GA4 property, while themodules/analyticsstore'sselectPropertyaction should be used to empty/reset the UA property (since that then needs to later be chosen in another dropdown based on the GA4 property). - Otherwise or if the selected property is a UA property, the
setPrimaryPropertyTypeaction should be called to indicate "ua". Then, themodules/analyticsstore'sselectPropertyaction should be used to set the UA property, while themodules/analytics-4store'sselectPropertyaction should be used to empty/reset the GA4 property (since that then needs to later be chosen in another dropdown based on the GA4 property).
- If the selected property is a GA4 property, the
- Storybook coverage for the new component should be added, with data including both UA and GA4 properties.
Implementation Brief
This will involve taking code from the GA and GA4 PropertySelects (currently in progress on https://github.com/google/site-kit-wp/issues/3166), and also the changes for rending null in https://github.com/google/site-kit-wp/issues/3243
As mentioned in the AC, the changes will be using the selector getPropertiesIncludingGA4, and using the code for rendering the <Option> from both the UA and GA4 PropertySelect's (switching based on the property type - check for keys _id vs id e.g. https://github.com/google/site-kit-wp/blob/develop/assets/js/modules/analytics/datastore/properties.js#L484)
Pay attention to the rules in the AC about which property to show selected, and how to set that property (the AC is very descriptive)
Create new storybook stories for this, copying the existing UA and GA4 PropertySelect stories
Test Coverage
Using the existing tests for assets/js/modules/analytics-4/components/common/PropertySelect.test.js and assets/js/modules/analytics/components/common/PropertySelect.test.js, the new tests will have all these tests (selecting an option, displaying an option, rendering a list of options) with both UA and GA4 fixtures.
Select a UA property, select a GA4 property, etc
Visual Regression Changes
The PR for Implement GA4 PropertySelect component in JS https://github.com/google/site-kit-wp/issues/3166 has no extra VRTs, so none are needed for this.
QA Brief
- Observe story https://google.github.io/site-kit-wp/storybook/pull/3383/?path=/story/analytics-module--property-select-including-ga4-properties "Property Select including GA4 properties" in "Analytics Module". It shows GA4 and UA properties (and both can be selected)
Changelog entry
- Add Analytics property select component for showing all UA and GA4 properties.
@danielgent I will approve this IB but next time could you please elaborate a little bit more on details? Try to give more clear details of what needs to be done and what to use.
Also, I am going to bump the estimate to 11 since 7 seems to be low for me (knowing that this ticket involves js tests and storybook changes).
IB :heavy_check_mark:
@eugene-manuilov I was struggling to explain this further without just doing the PR!! :smile: As it involves copying, pasting, and slightly modifying existing code (even deciding whether a property is GA4 or UA can be taken from my already-existing code)
Honestly I was thinking even less than 7 as it involves copying and pasting from existing files :see_no_evil: (happy to be proved wrong though!!! I've estimated way way under before)
Just a head's up that these two requirements involve changing the code in ways that are out the scope of this ticket @felixarntz @eugene-manuilov
- the modules/analytics store's selectProperty action should be used to empty/reset the UA property
- the modules/analytics-4 store's selectProperty action should be used to empty/reset the GA4 property
For both stores, selectProperty requires a valid ID e.g.
selectProperty( propertyID, internalPropertyID = '' ) {
invariant( isValidPropertySelection( propertyID ), 'A valid propertyID selection is required.' );
So I can't empty/reset them!
I tried removing these invariants but then other things started to explode: see my commit here (which fails tests and linting)
https://github.com/google/site-kit-wp/commit/3b207af7229daf04ce54d48612e90373fb6a0363
Currently it fails when setting the GA4 propertyID to null. I'm not going to investigate further as this is an error with the @material library, and I already know of one existing bug that we have with these :smile:
● PropertySelectIncludingGA4 › should update propertyID in the UA store when a new UA item is selected
TypeError: Cannot read property 'length' of null
193 |
194 | // "length null error" is something inside @material component
> 195 | fireEvent.click( getAllByRole( 'menuitem', { hidden: true } )[ 7 ] );
| ^
196 |
197 | expect( registry.select( MODULES_ANALYTICS ).getPrimaryPropertyType() ).toBe( 'ua' );
198 |
at e.foundation [as handleChange] (node_modules/@material/react-select/dist/webpack:/packages/select/node_modules/@material/select/foundation.js:140:36)
at e.componentDidUpdate (node_modules/@material/react-select/dist/webpack:/packages/select/index.tsx:152:18)
at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:22117:22)
```
@danielgent let's use the following instead of changing selectProperty selectors:
// for the analytics module:
registry.dispatch( MODLUES_ANALYTICS ).setPropertyID( '' );
registry.dispatch( MODLUES_ANALYTICS ).setInternalWebPropertyID( '' );
registry.dispatch( MODLUES_ANALYTICS ).setProfileID( '' );
// for the analytics-4 module:
registry.dispatch( MODLUES_ANALYTICS_4 ).setPropertyID( '' );
registry.dispatch( MODLUES_ANALYTICS_4 ).setWebDataStreamID( '' );
registry.dispatch( MODLUES_ANALYTICS_4 ).setMeasurementID( '' );
Thanks for the suggestion @eugene-manuilov
I did try this though (copying the empty string passed to setWebDataStreamID) but sadly it doesn't work
the setPropertyID have invariants that call isValidPropertySelection which calls isValidPropertyID
export function isValidPropertyID( propertyID ) {
return typeof propertyID === 'string' && /^UA-\d+-\d+$/.test( propertyID );
}
Which does not match empty strings :smile:

@danielgent how come it doesn't work :thinking:? Those actions are autogenerated and the only thing they validate is that the incoming value doesn't equal undefined: https://github.com/google/site-kit-wp/blob/1181d49b512d3fb79ebd6ff858a96db32197fd12/assets/js/googlesitekit/data/create-settings-store.js#L302-L309
Can you try again or show me an example of what you are doing?
Apologies @eugene-manuilov
I'd misread :facepalm:
What you wrote works perfectly! Thanks :+1:
QA ✅
Double checked the code and verified that the story works as described in the QAB.