site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Implement GA4 PropertySelect component in JS

Open felixarntz opened this issue 5 years ago • 7 comments

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 PropertySelect component in assets/js/modules/analytics-4/components/common/PropertySelect.js which at a high level does the same that the existing Analytics (UA) PropertySelect component does, just for GA4 properties instead.
    • It should rely on the modules/analytics-4 datastore:
      • 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 PropertySelect component).
    • 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.
  • There should be Storybook coverage for the new component.

Implementation Brief

  • Create file assets/js/modules/analytics-4/components/common/PropertySelect.js which exports the PropertySelect functional component.
  • 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.
    • Disregard all references to hasExistingTag which is not in scope for now.
  • Add stories for the newly added PropertySelect component in assets/js/modules/analytics-4/components/common/PropertySelect.stories.js.

Test Coverage

  • Add tests for the PropertySelect component.

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 assets/js/modules/analytics-4/components/common/PropertySelect.stories.js (see: https://github.com/google/site-kit-wp/pull/3221#discussion_r629584884) stories/module-analytics-4.stories.js.
  • There should be test coverage for the new component.

Changelog entry

  • N/A

felixarntz avatar Apr 15 '21 21:04 felixarntz

IB ✅

tofumatt avatar Apr 21 '21 09:04 tofumatt

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 avatar Apr 26 '21 15:04 johnPhillips

@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.

felixarntz avatar Apr 26 '21 17:04 felixarntz

Perfect, thanks @felixarntz

johnPhillips avatar Apr 26 '21 17:04 johnPhillips

@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 PropertySelect component 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 PropertySelect dropdown.

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 avatar Apr 27 '21 12:04 johnPhillips

@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.

felixarntz avatar Apr 27 '21 18:04 felixarntz

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 🙂

tofumatt avatar May 17 '21 22:05 tofumatt