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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f135962
Add `isWebDataStreamNotAvailable` state, selector and action.
kuasha420 Apr 3, 2023
229781d
Update `syncGoogleTagSettings` action.
kuasha420 Apr 3, 2023
fd4a30e
Add `WebDataStreamNotAvailableNotification` component.
kuasha420 Apr 3, 2023
cf111fc
Add to BannerNotifications.
kuasha420 Apr 3, 2023
c91b2e2
Update `GA4SettingsControls` component.
kuasha420 Apr 3, 2023
e50f7e4
Fix typo missing commas thanks prettier.
kuasha420 Apr 3, 2023
2715399
Fix ErrorText usages.
kuasha420 Apr 4, 2023
bb7ca5c
Move the action above.
kuasha420 Apr 4, 2023
301bd16
Update `syncGoogleTagSettings` test.
kuasha420 Apr 4, 2023
50ecf97
Add tests for new selector and action.
kuasha420 Apr 4, 2023
93f3528
Add story for `WebDataStreamNotAvailableNotification`.
kuasha420 Apr 4, 2023
812fb85
Update `GA4SettingsControls`.
kuasha420 Apr 4, 2023
d6050bd
Merge branch 'main' into bug/6763-web-data-stream-not-available.
kuasha420 Apr 5, 2023
b07d938
Only show error messages if the field is not disabled and user has mo…
kuasha420 Apr 6, 2023
4141e46
Add VRT images for banner.
kuasha420 Apr 6, 2023
579c2b0
Fix flipper logic.
kuasha420 Apr 7, 2023
2060cbb
Merge branch 'develop' into bug/6763-web-data-stream-not-available.
kuasha420 Apr 7, 2023
4400235
Adding stories WIP.
kuasha420 Apr 7, 2023
73c3b6e
Fix PropertyNotAvailable and WebDataStreamNotAvailable and add scenar…
techanvil Apr 7, 2023
962c1b9
Add scenario for the WithGA4Tag story that the previous commit also f…
techanvil Apr 7, 2023
9445d00
Add VRT reference images.
techanvil Apr 7, 2023
c7e0e71
Merge branch 'develop' into bug/6763-web-data-stream-not-available.
kuasha420 Apr 9, 2023
c6dbad1
Fix import of `Grid`.
kuasha420 Apr 9, 2023
02d47d1
Add a comment explaining the dismissExpire value.
kuasha420 Apr 9, 2023
29a1737
Update copy with full stop.
kuasha420 Apr 13, 2023
4052338
Fix typo and capitalization in test.
kuasha420 Apr 13, 2023
f310cc1
Rename selector and related code.
kuasha420 Apr 13, 2023
294b259
Merge branch 'develop' into bug/6763-web-data-stream-not-available
kuasha420 Apr 13, 2023
0ce8421
Extract property and web data stream related error message to separat…
kuasha420 Apr 13, 2023
a0e5e9d
Fix tests.
kuasha420 Apr 13, 2023
d19d51a
Update VRT reference images.
kuasha420 Apr 13, 2023
46b7d4d
Remove unnecessary elseif.
kuasha420 Apr 14, 2023
47d7c6f
Revert unnecessary noise introduced while fixing merge conflict.
kuasha420 Apr 14, 2023
6217eab
Add tests for `PropertyOrWebDataStreamNotAvailableError`.
kuasha420 Apr 14, 2023
126f8b9
Check for `false` not `false`-y for the get properties selector error.
tofumatt Apr 14, 2023
c57a47e
Merge branch 'develop' into bug/6763-web-data-stream-not-available.
tofumatt Apr 14, 2023
3ecfabd
Merge branch 'develop' into bug/6763-web-data-stream-not-available.
tofumatt Apr 14, 2023
5203129
Reset the property ID when selecting a different account.
tofumatt Apr 16, 2023
91a390f
Restore false-y checks for error.
tofumatt Apr 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions assets/js/components/notifications/BannerNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import EnableAutoUpdateBannerNotification from './EnableAutoUpdateBannerNotifica
import GoogleTagIDMismatchNotification from './GoogleTagIDMismatchNotification';
import SwitchGA4DashboardViewNotification from './SwitchGA4DashboardViewNotification';
import { GTM_SCOPE } from '../../modules/analytics-4/datastore/constants';
import WebDataStreamNotAvailableNotification from './WebDataStreamNotAvailableNotification';

const { useSelect } = Data;

Expand Down Expand Up @@ -84,9 +85,12 @@ export default function BannerNotifications() {
{ isAuthenticated && <CoreSiteBannerNotifications /> }
{ dashboardSharingEnabled && <ModuleRecoveryAlert /> }
{ ga4ActivationBannerEnabled && <ActivationBanner /> }
{ gteSupportEnabled &&
ga4ModuleConnected &&
hasGTMScope && <GoogleTagIDMismatchNotification /> }
{ gteSupportEnabled && ga4ModuleConnected && hasGTMScope && (
<Fragment>
<GoogleTagIDMismatchNotification />
<WebDataStreamNotAvailableNotification />
Comment on lines +90 to +91
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.

</Fragment>
) }
</Fragment>
) }
<ZeroDataStateNotifications />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* WebDataStreamNotAvailableNotification component.
*
* Site Kit by Google, Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { ProgressBar } from 'googlesitekit-components';
import Data from 'googlesitekit-data';
import BannerNotification from './BannerNotification';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import { getTimeInSeconds } from '../../util';
import { Cell, Grid, Row } from '../../material-components';

const { useSelect } = Data;

export default function WebDataStreamNotAvailableNotification() {
const isWebDataStreamAvailable = useSelect( ( select ) =>
select( MODULES_ANALYTICS_4 ).isWebDataStreamAvailable()
);

const measurementID = useSelect( ( select ) =>
select( MODULES_ANALYTICS_4 ).getMeasurementID()
);

const settingsURL = useSelect( ( select ) =>
select( CORE_SITE ).getAdminURL( 'googlesitekit-settings' )
);

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

if ( measurementID === undefined ) {
// Wrap in the googlesitekit-publisher-win class to ensure the output is treated in the same way as BannerNotification,
// with only one instance visible on the screen at a time.
return (
<div className="googlesitekit-publisher-win">
<Grid>
<Row>
<Cell size={ 12 }>
<ProgressBar />
</Cell>
</Row>
</Grid>
</div>
);
}

return (
<BannerNotification
id="web-data-stream-not-available"
title={ __(
'Your Analytics 4 configuration has changed',
'google-site-kit'
) }
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.',
'google-site-kit'
),
measurementID
) }
ctaLink={ `${ settingsURL }#connected-services/analytics/edit` }
ctaLabel={ __( 'Update Analytics settings', 'google-site-kit' ) }
dismiss={ __( 'Maybe later', 'google-site-kit' ) }
// This is arbitrarily set to 55 minutes to ensure that the notification
// will become ready to be displayed again in an hour.
dismissExpires={ getTimeInSeconds( 'minute' ) * 55 }
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* WebDataStreamNotAvailableNotification Component stories.
*
* Site Kit by Google, Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import WithRegistrySetup from '../../../../tests/js/WithRegistrySetup';
import { MODULES_ANALYTICS } from '../../modules/analytics/datastore/constants';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';
import WebDataStreamNotAvailableNotification from './WebDataStreamNotAvailableNotification';

function Template( { ...args } ) {
return <WebDataStreamNotAvailableNotification { ...args } />;
}

export const Loading = Template.bind( {} );
Loading.storyName = 'Loading';

export const Default = Template.bind( {} );
Default.storyName = 'Default';
Default.decorators = [
( Story ) => {
const setupRegistry = ( registry ) => {
registry
.dispatch( MODULES_ANALYTICS_4 )
.setMeasurementID( 'G-2B7M8YQ1K6' );
};

return (
<WithRegistrySetup func={ setupRegistry }>
<Story />
</WithRegistrySetup>
);
},
];
Default.scenario = {
label: 'Global/WebDataStreamNotAvailableNotification/Default',
};

export default {
title: 'Components/WebDataStreamNotAvailableNotification',
component: WebDataStreamNotAvailableNotification,
decorators: [
( Story ) => {
const setupRegistry = ( registry ) => {
registry.dispatch( MODULES_ANALYTICS ).setSettings( {} );

registry
.dispatch( MODULES_ANALYTICS_4 )
.setIsWebDataStreamAvailable( false );

registry.dispatch( MODULES_ANALYTICS_4 ).setSettings( {} );
};

return (
<WithRegistrySetup func={ setupRegistry }>
<Story />
</WithRegistrySetup>
);
},
],
};
40 changes: 36 additions & 4 deletions assets/js/modules/analytics-4/datastore/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ const fetchGetGoogleTagSettingsStore = createFetchStore( {
const WAIT_FOR_PROPERTIES = 'WAIT_FOR_PROPERTIES';
const MATCHING_ACCOUNT_PROPERTY = 'MATCHING_ACCOUNT_PROPERTY';
const SET_HAS_MISMATCHED_TAG = 'SET_HAS_MISMATCHED_GOOGLE_TAG_ID';
const SET_IS_WEBDATASTREAM_AVAILABLE = 'SET_IS_WEBDATASTREAM_AVAILABLE';

const baseInitialState = {
properties: {},
propertiesByID: {},
hasMismatchedTag: false,
isMatchingAccountProperty: false,
isWebDataStreamAvailable: true,
};

const baseActions = {
Expand Down Expand Up @@ -525,6 +527,21 @@ const baseActions = {
};
},

/**
* Sets whether the Web Data Stream is available.
*
* @since n.e.x.t
*
* @param {boolean} isWebDataStreamAvailable Whether the Web Data Stream is available.
* @return {Object} Redux-style action.
*/
*setIsWebDataStreamAvailable( isWebDataStreamAvailable ) {
return {
type: SET_IS_WEBDATASTREAM_AVAILABLE,
payload: { isWebDataStreamAvailable },
};
},

/**
* Syncs Google Tag settings.
*
Expand Down Expand Up @@ -590,10 +607,8 @@ const baseActions = {
);

if ( ! googleTagContainer ) {
return;
}

if ( ! googleTagContainer.tagIds.includes( googleTagID ) ) {
yield baseActions.setIsWebDataStreamAvailable( false );
} else if ( ! googleTagContainer.tagIds.includes( googleTagID ) ) {
yield baseActions.setHasMismatchedGoogleTagID( true );
}
} else {
Expand Down Expand Up @@ -630,6 +645,11 @@ function baseReducer( state, { type, payload } ) {
...state,
hasMismatchedTag: payload.hasMismatchedTag,
};
case SET_IS_WEBDATASTREAM_AVAILABLE:
return {
...state,
isWebDataStreamAvailable: payload.isWebDataStreamAvailable,
};
default:
return state;
}
Expand Down Expand Up @@ -713,6 +733,18 @@ const baseSelectors = {
hasMismatchedGoogleTagID( state ) {
return state.hasMismatchedTag;
},

/**
* Checks if the Web Data Stream is available.
*
* @since n.e.x.t
*
* @param {Object} state Data store's state.
* @return {boolean} TRUE if the Web Data Stream is available, otherwise FALSE.
*/
isWebDataStreamAvailable( state ) {
return state.isWebDataStreamAvailable;
},
};

const store = Data.combineStores(
Expand Down
Loading