Skip to content
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

Bug/6763 web data stream not available #6816

Merged
merged 39 commits into from
Apr 17, 2023

Conversation

kuasha420
Copy link
Contributor

@kuasha420 kuasha420 commented Apr 4, 2023

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 5.6.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions
Copy link

github-actions bot commented Apr 4, 2023

Size Change: +670 B (0%)

Total Size: 1.24 MB

Filename Size Change
./dist/assets/js/googlesitekit-activation-********************.js 22.6 kB +1 B (0%)
./dist/assets/js/googlesitekit-adminbar-********************.js 31.8 kB -12 B (0%)
./dist/assets/js/googlesitekit-api-********************.js 9.6 kB -2 B (0%)
./dist/assets/js/googlesitekit-components-gm2-********************.js 6.11 kB -1 B (0%)
./dist/assets/js/googlesitekit-data-********************.js 2.17 kB -4 B (0%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.22 kB -4 B (0%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 16.3 kB -3 B (0%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 22.5 kB -106 B (0%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 63.4 kB +34 B (0%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 74.9 kB +289 B (0%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 74.4 kB +28 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 28.1 kB +86 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-********************.js 82.9 kB +320 B (0%)
./dist/assets/js/googlesitekit-modules-optimize-********************.js 19 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 21.3 kB -2 B (0%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 51.2 kB +36 B (0%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32.3 kB +1 B (0%)
./dist/assets/js/googlesitekit-settings-********************.js 47.1 kB +8 B (0%)
./dist/assets/js/googlesitekit-splash-********************.js 65.1 kB -14 B (0%)
./dist/assets/js/googlesitekit-user-input-********************.js 39.9 kB -4 B (0%)
./dist/assets/js/googlesitekit-vendor-********************.js 319 kB +16 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 16.6 kB +2 B (0%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 60.2 kB -2 B (0%)
./dist/assets/js/runtime-********************.js 1.26 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 48.5 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.1 kB
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 7.41 kB
./dist/assets/js/29-********************.js 2.8 kB
./dist/assets/js/30-********************.js 2.28 kB
./dist/assets/js/31-********************.js 3.72 kB
./dist/assets/js/32-********************.js 3.12 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 769 B
./dist/assets/js/googlesitekit-components-gm3-********************.js 9.73 kB
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB
./dist/assets/js/googlesitekit-datastore-ui-********************.js 9.3 kB
./dist/assets/js/googlesitekit-i18n-********************.js 3.92 kB
./dist/assets/js/googlesitekit-modules-********************.js 20.8 kB
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B

compressed-size-action

@kuasha420 kuasha420 changed the base branch from develop to main April 5, 2023 08:56
@kuasha420 kuasha420 changed the base branch from main to develop April 5, 2023 14:10
@@ -222,6 +281,10 @@ WithGA4Tag.decorators = [
);
},
];
WithGA4Tag.scenario = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This story had degenerated into a broken state, and was fixed as a byproduct of this PR. This scenario was therefore added to provide some additional test coverage.

Comment on lines +90 to +91
<GoogleTagIDMismatchNotification />
<WebDataStreamNotAvailableNotification />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This order may need some thinking as it was not defined in AC/IB, but this made sense to me while implementing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me too, I think that's fine 👍🏻

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This placement seems incorrect because the component doesn't depend on GTE or the GTM scope. It should however be only shown to authenticated users since it uses module settings which won't be available in a view-only context.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further review, it seems okay since the code that triggers it only happens when syncing Google tag settings so while this seems off at first glance, it should be fine.

Comment on lines 145 to 235
{ isDisabled && (
{ isDisabled ? (
<GA4ActivateSwitch
disabled={ ! hasAnalyticsAccess }
onActivate={ onActivate }
/>
) }

{ ! isDisabled && (
) : (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated refactor that was needed to satisfy the cyclometic complexity eslint rules. 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's a real shame. I always find ternaries in JSX to be a nightmare to read and have frequently discouraged their use in the codebase up until now.

I'd much rather eslint-disable this rule here than satisfy it. It increases the complexity by changing two independent sections into one single section.

Ternaries are great for one-line, easily readable variable assignments, but for multiline, multi-component JSX like this they're brutal to follow.

Can this rule be disabled here with a note explaining that the ternary makes it harder to read?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just chipping in here to say, I think disabling the complexity rule here would be the wrong approach - it would be necessary to disable it for the whole function, meaning this function could continue to grow more complex with no limit to it. It seems a bit of a slippery slope to start disabling the rule like this.

If this refactor is objectionable, I'd suggest taking a different approach to refactoring the function rather than disabling the rule entirely...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@techanvil @tofumatt yep, disabling the rule is per function and not per line so disabling the rule will really bite us in the future. I can try to find other way to claim back another execution path without this specific refactor, but as far as I remember this was the most straightforward and reasonable one 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't mind the ternary here, but @tofumatt does seem quite strongly against it and I don't have a strong enough opinion on the matter to argue the point :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I had to extract out the error related logic to a separate component anyway, as there were a few more changes that came from other merged PRs that put the complexity to the roof. Hence, I have reverted this change here but made @tofumatt's life harder by introducing another component and corresponding tests 😅

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, very minor copy edit change and a thought about the variable/selector naming here.

After that should be good to merge 👍🏻

Comment on lines +90 to +91
<GoogleTagIDMismatchNotification />
<WebDataStreamNotAvailableNotification />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me too, I think that's fine 👍🏻

description={ sprintf(
/* translators: 1: Google Analytics 4 Measurement ID. */
__(
'The previously selected web data stream with measurement ID %1$s is no longer available. Please select a new web data stream to continue collecting data with Google Analytics 4',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'The previously selected web data stream with measurement ID %1$s is no longer available. Please select a new web data stream to continue collecting data with Google Analytics 4',
'The previously selected web data stream with measurement ID %1$s is no longer available. Please select a new web data stream to continue collecting data with Google Analytics 4.',

@@ -889,6 +911,92 @@ describe( 'modules/analytics-4 properties', () => {
).toEqual( googleTagID );
} );

it( 'should set `isWebDataStreamNotAvailable` to `true` when there is no google tag conainer available', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it( 'should set `isWebDataStreamNotAvailable` to `true` when there is no google tag conainer available', async () => {
it( 'should set `isWebDataStreamNotAvailable` to `true` when there is no Google Tag Container available', async () => {

* @param {Object} state Data store's state.
* @return {boolean} If the Web Data Stream is not available.
*/
isWebDataStreamNotAvailable( state ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was all spelled out in the IB, but the selector/data used here is a double-negative, which is a bit harder to reason about. The data stream is available when "is not available is false".

It might be a bit easier to reason about these values if the selector/data instead was isWebDataStreamAvailable and it was set to true by default.

We only use the selector in one place (https://github.com/google/site-kit-wp/pull/6816/files#diff-2b5924118d9c2ea36627f1a4869ae7400537225ece2b18d3256354cf1046ad80R50), but I think it'd be easier to read:

// If the data stream is available, we don't have to show a warning to the user.
if ( isWebDataStreamAvailable ) {
  return null;
}

instead of:

if ( ! isWebDataStreamNotAvailable ) {
  return null;
}

Comment on lines 145 to 235
{ isDisabled && (
{ isDisabled ? (
<GA4ActivateSwitch
disabled={ ! hasAnalyticsAccess }
onActivate={ onActivate }
/>
) }

{ ! isDisabled && (
) : (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's a real shame. I always find ternaries in JSX to be a nightmare to read and have frequently discouraged their use in the codebase up until now.

I'd much rather eslint-disable this rule here than satisfy it. It increases the complexity by changing two independent sections into one single section.

Ternaries are great for one-line, easily readable variable assignments, but for multiline, multi-component JSX like this they're brutal to follow.

Can this rule be disabled here with a note explaining that the ternary makes it harder to read?

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this before—so I'm not sure if it's due to some changes since the PR or if this was always happening, but I see a brief flash of the message when changing GA4 accounts in the Settings Edit component:

CleanShot.2023-04-14.at.19.04.17.mp4

It's worth noting some of these accounts are older but I think I actually do have access to them so the data stream should be available? It seems to happen while the GA4 data for that account is loading, as it goes away and doesn't appear instantly. So there's probably a condition for displaying the error that isn't quite right 🤔

);
}

if ( ! propertyAvailable && ! getPropertiesError ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( ! propertyAvailable && ! getPropertiesError ) {
if ( ! propertyAvailable && getPropertiesError === false ) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is what was causing the bug I encountered: getPropertiesError can be undefined (for instance, while loading) and it causes a flag of this message when no property is available and there's no error.

Changing this to === false fixes the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong about that, the issue is actually that the previously-selected property for an old account isn't reset until the new properties are loaded, meaning there's a time when the property ID is valid while things are still loading.

The trick should be "resetting" the property ID to be undefined when the account changes.

@tofumatt
Copy link
Collaborator

I needed to make this change: 5203129 to get everything working and prevent this error: #6816 (review).

I've otherwise code-reviewed this PR and it looks good, but I'd appreciate a quick MR to make sure this won't cause any problems I haven't noticed. In my testing with GA4 Reporting feature flag on and off, and settings for all combinations of both/either modules, it worked fine.

But it'd be good to get another set of eyes on just this commit: 5203129

@tofumatt
Copy link
Collaborator

Actually I think this is safe to merge, we can always revert my small change if needed.

@tofumatt tofumatt merged commit 230fae3 into develop Apr 17, 2023
@tofumatt tofumatt deleted the bug/6763-web-data-stream-not-available branch April 17, 2023 09:29
@kuasha420
Copy link
Contributor Author

@tofumatt Thank you for spotting the edge case, figuring out a fix for it and getting this merged. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants