@@ -24,23 +24,44 @@ import PropTypes from 'prop-types';
2424/**
2525 * WordPress dependencies
2626 */
27- import { useEffect , useState } from '@wordpress/element' ;
27+ import {
28+ createInterpolateElement ,
29+ useEffect ,
30+ useState ,
31+ } from '@wordpress/element' ;
2832import { __ } from '@wordpress/i18n' ;
2933
3034/**
3135 * Internal dependencies
3236 */
33- import { SpinnerButton } from 'googlesitekit-components' ;
34- import { useSelect } from 'googlesitekit-data' ;
37+ import { SpinnerButton , Button } from 'googlesitekit-components' ;
38+ import { useSelect , useDispatch } from 'googlesitekit-data' ;
3539import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants' ;
3640import { MODULES_ANALYTICS_4 } from '@/js/modules/analytics-4/datastore/constants' ;
3741import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants' ;
3842import { CORE_LOCATION } from '@/js/googlesitekit/datastore/location/constants' ;
43+ import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants' ;
44+ import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants' ;
3945import useActivateModuleCallback from '@/js/hooks/useActivateModuleCallback' ;
4046import useCompleteModuleActivationCallback from '@/js/hooks/useCompleteModuleActivationCallback' ;
4147import { useDebounce } from '@/js/hooks/useDebounce' ;
48+ import { useFeature } from '@/js/hooks/useFeature' ;
49+ import Link from '@/js/components/Link' ;
50+ import AnalyticsIcon from '@/svg/graphics/analytics.svg' ;
51+
52+ export default function ActivateAnalyticsCTA ( {
53+ children,
54+ dismissedItemSlug,
55+ } ) {
56+ const setupFlowRefreshEnabled = useFeature ( 'setupFlowRefresh' ) ;
57+
58+ const isDismissed = useSelect ( ( select ) => {
59+ if ( ! setupFlowRefreshEnabled ) {
60+ return false ;
61+ }
62+ return select ( CORE_USER ) . isItemDismissed ( dismissedItemSlug ) ;
63+ } ) ;
4264
43- export default function ActivateAnalyticsCTA ( { children } ) {
4465 const activateModuleCallback = useActivateModuleCallback (
4566 MODULE_SLUG_ANALYTICS_4
4667 ) ;
@@ -57,6 +78,14 @@ export default function ActivateAnalyticsCTA( { children } ) {
5778 ! ! select ( MODULES_ANALYTICS_4 )
5879 ) ;
5980 } ) ;
81+
82+ const documentationURL = useSelect ( ( select ) => {
83+ if ( ! setupFlowRefreshEnabled ) {
84+ return null ;
85+ }
86+ return select ( CORE_SITE ) . getDocumentationLinkURL ( 'ga4' ) ;
87+ } ) ;
88+
6089 const [ inProgress , setInProgress ] = useState ( false ) ;
6190
6291 const isNavigatingToReauthURL = useSelect ( ( select ) => {
@@ -100,6 +129,8 @@ export default function ActivateAnalyticsCTA( { children } ) {
100129 }
101130 } , [ isActivating , isNavigatingToReauthURL , debouncedSetInProgress ] ) ;
102131
132+ const { dismissItem } = useDispatch ( CORE_USER ) ;
133+
103134 const onClickCallback = analyticsModuleActive
104135 ? completeModuleActivationCallback
105136 : activateModuleCallback ;
@@ -108,32 +139,82 @@ export default function ActivateAnalyticsCTA( { children } ) {
108139 return null ;
109140 }
110141
111- return (
112- < div className = "googlesitekit-analytics-cta" >
113- < div className = "googlesitekit-analytics-cta__preview-graphs" >
114- { children }
142+ if ( setupFlowRefreshEnabled && isDismissed ) {
143+ return null ;
144+ }
145+
146+ if ( ! setupFlowRefreshEnabled ) {
147+ return (
148+ < div className = "googlesitekit-analytics-cta" >
149+ < div className = "googlesitekit-analytics-cta__preview-graphs" >
150+ { children }
151+ </ div >
152+ < div className = "googlesitekit-analytics-cta__details" >
153+ < p className = "googlesitekit-analytics-cta--description" >
154+ { __ (
155+ 'See how many people visit your site from Search and track how you’re achieving your goals' ,
156+ 'google-site-kit'
157+ ) }
158+ </ p >
159+ < SpinnerButton
160+ onClick = { onClickCallback }
161+ isSaving = { inProgress }
162+ disabled = { inProgress }
163+ >
164+ { analyticsModuleActive
165+ ? __ ( 'Complete setup' , 'google-site-kit' )
166+ : __ (
167+ 'Set up Google Analytics' ,
168+ 'google-site-kit'
169+ ) }
170+ </ SpinnerButton >
171+ </ div >
115172 </ div >
116- < div className = "googlesitekit-analytics-cta__details" >
117- < p className = "googlesitekit-analytics-cta--description" >
118- { __ (
119- 'See how many people visit your site from Search and track how you’re achieving your goals' ,
120- 'google-site-kit'
173+ ) ;
174+ }
175+
176+ return (
177+ < div className = "googlesitekit-activate-analytics-cta" >
178+ < div className = "googlesitekit-activate-analytics-cta__top" >
179+ < div className = "googlesitekit-activate-analytics-cta__icon" >
180+ < AnalyticsIcon width = { 28 } height = { 31 } />
181+ </ div >
182+ < p className = "googlesitekit-activate-analytics-cta__description" >
183+ { createInterpolateElement (
184+ __ (
185+ 'See how many people visit your site from Search and track how you’re achieving your goals. <a>Learn more</a>' ,
186+ 'google-site-kit'
187+ ) ,
188+ {
189+ a : < Link href = { documentationURL } external /> ,
190+ }
121191 ) }
122192 </ p >
193+ </ div >
194+ < div className = "googlesitekit-activate-analytics-cta__actions" >
195+ < Button
196+ className = "googlesitekit-activate-analytics-cta__button--secondary"
197+ onClick = { ( ) => dismissItem ( dismissedItemSlug ) }
198+ tertiary
199+ >
200+ { __ ( 'Maybe later' , 'google-site-kit' ) }
201+ </ Button >
123202 < SpinnerButton
203+ className = "googlesitekit-activate-analytics-cta__button--primary"
124204 onClick = { onClickCallback }
125205 isSaving = { inProgress }
126206 disabled = { inProgress }
127207 >
128208 { analyticsModuleActive
129209 ? __ ( 'Complete setup' , 'google-site-kit' )
130- : __ ( 'Set up Google Analytics' , 'google-site-kit' ) }
210+ : __ ( 'Set up Analytics' , 'google-site-kit' ) }
131211 </ SpinnerButton >
132212 </ div >
133213 </ div >
134214 ) ;
135215}
136216
137217ActivateAnalyticsCTA . propTypes = {
138- children : PropTypes . node . isRequired ,
218+ children : PropTypes . node ,
219+ dismissedItemSlug : PropTypes . string . isRequired ,
139220} ;
0 commit comments