-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6752 from google/enhance/6544-switch-to-ga4-banner
Add `shouldPromptGA4DashboardView` selector and `SwitchGA4DashboardViewNotification` component.
- Loading branch information
Showing
10 changed files
with
390 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
assets/js/components/notifications/SwitchGA4DashboardViewNotification.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* SwitchGA4DashboardViewNotification 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 { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Data from 'googlesitekit-data'; | ||
import BannerNotification from './BannerNotification'; | ||
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants'; | ||
import { | ||
DASHBOARD_VIEW_GA4, | ||
MODULES_ANALYTICS, | ||
} from '../../modules/analytics/datastore/constants'; | ||
import GA4SuccessGreenSVG from '../../../svg/graphics/ga4-success-green.svg'; | ||
|
||
const { useDispatch, useSelect } = Data; | ||
|
||
export default function SwitchGA4DashboardViewNotification() { | ||
const shouldPromptGA4DashboardView = useSelect( ( select ) => | ||
select( MODULES_ANALYTICS ).shouldPromptGA4DashboardView() | ||
); | ||
|
||
const ga4DocumentationURL = useSelect( ( select ) => | ||
select( CORE_SITE ).getDocumentationLinkURL( 'ga4' ) | ||
); | ||
|
||
const { setDashboardView, saveSettings } = useDispatch( MODULES_ANALYTICS ); | ||
|
||
const handleCTAClick = async () => { | ||
await setDashboardView( DASHBOARD_VIEW_GA4 ); | ||
await saveSettings(); | ||
}; | ||
|
||
if ( ! shouldPromptGA4DashboardView ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<BannerNotification | ||
id="switch-ga4-dashboard-view" | ||
title={ __( | ||
'Display data from Google Analytics 4 on your dashboard', | ||
'google-site-kit' | ||
) } | ||
description={ __( | ||
'Update your dashboard to show data from the new version of Analytics (Google Analytics 4) instead of the old version (Universal Analytics).', | ||
'google-site-kit' | ||
) } | ||
ctaLink="#" | ||
ctaLabel={ __( 'Update dashboard', 'google-site-kit' ) } | ||
onCTAClick={ handleCTAClick } | ||
dismiss={ __( 'Maybe later', 'google-site-kit' ) } | ||
WinImageSVG={ GA4SuccessGreenSVG } | ||
learnMoreLabel={ __( 'Learn what’s new', 'google-site-kit' ) } | ||
learnMoreURL={ ga4DocumentationURL } | ||
/> | ||
); | ||
} |
73 changes: 73 additions & 0 deletions
73
assets/js/components/notifications/SwitchGA4DashboardViewNotification.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* SwitchGA4DashboardViewNotification 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 { | ||
DASHBOARD_VIEW_UA, | ||
MODULES_ANALYTICS, | ||
} from '../../modules/analytics/datastore/constants'; | ||
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants'; | ||
import SwitchGA4DashboardViewNotification from './SwitchGA4DashboardViewNotification'; | ||
import { | ||
createTestRegistry, | ||
provideModules, | ||
provideSiteInfo, | ||
WithTestRegistry, | ||
} from '../../../../tests/js/utils'; | ||
import { enabledFeatures } from '../../features'; | ||
|
||
function Template( { ...args } ) { | ||
return <SwitchGA4DashboardViewNotification { ...args } />; | ||
} | ||
|
||
export const SwitchGA4DashboardViewNotificationDefault = Template.bind( {} ); | ||
SwitchGA4DashboardViewNotificationDefault.storyName = 'Default'; | ||
|
||
export default { | ||
title: 'Components/SwitchGA4DashboardViewNotification', | ||
component: SwitchGA4DashboardViewNotification, | ||
decorators: [ | ||
( Story ) => { | ||
enabledFeatures.add( 'ga4Reporting' ); | ||
const registry = createTestRegistry(); | ||
provideSiteInfo( registry ); | ||
provideModules( registry, [ | ||
{ | ||
slug: 'analytics-4', | ||
active: true, | ||
connected: true, | ||
}, | ||
] ); | ||
|
||
registry.dispatch( MODULES_ANALYTICS ).setSettings( { | ||
dashboardView: DASHBOARD_VIEW_UA, | ||
} ); | ||
|
||
registry | ||
.dispatch( MODULES_ANALYTICS_4 ) | ||
.receiveIsGatheringData( false ); | ||
return ( | ||
<WithTestRegistry registry={ registry }> | ||
<Story /> | ||
</WithTestRegistry> | ||
); | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.