@@ -39,6 +39,9 @@ import { __ } from '@wordpress/i18n';
3939import { Button , SpinnerButton } from 'googlesitekit-components' ;
4040import { useDispatch , useSelect } from 'googlesitekit-data' ;
4141import Link from '@/js/components/Link' ;
42+ import Typography from '@/js/components/Typography' ;
43+ import { SIZE_MEDIUM , TYPE_LABEL } from '@/js/components/Typography/constants' ;
44+ import P from '@/js/components/Typography/P' ;
4245import { CORE_LOCATION } from '@/js/googlesitekit/datastore/location/constants' ;
4346import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants' ;
4447import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants' ;
@@ -48,7 +51,10 @@ import useActivateModuleCallback from '@/js/hooks/useActivateModuleCallback';
4851import useCompleteModuleActivationCallback from '@/js/hooks/useCompleteModuleActivationCallback' ;
4952import { useDebounce } from '@/js/hooks/useDebounce' ;
5053import { useFeature } from '@/js/hooks/useFeature' ;
51- import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants' ;
54+ import {
55+ ANALYTICS_SETUP_ERROR ,
56+ MODULE_SLUG_ANALYTICS_4 ,
57+ } from '@/js/modules/analytics-4/constants' ;
5258import { MODULES_ANALYTICS_4 } from '@/js/modules/analytics-4/datastore/constants' ;
5359import AnalyticsIcon from '@/svg/graphics/analytics.svg' ;
5460
@@ -59,6 +65,9 @@ export default function ActivateAnalyticsCTA( {
5965} ) {
6066 const trackingRef = useRef ( ) ;
6167 const setupFlowRefreshEnabled = useFeature ( 'setupFlowRefresh' ) ;
68+ const setupFlowRefreshPhase4Enabled = useFeature (
69+ 'setupFlowRefreshPhase4'
70+ ) ;
6271
6372 const trackEvents = useNotificationEvents (
6473 'activate-analytics-cta' ,
@@ -102,6 +111,20 @@ export default function ActivateAnalyticsCTA( {
102111 return select ( CORE_SITE ) . getDocumentationLinkURL ( 'ga4' ) ;
103112 } ) ;
104113
114+ const hasActivationError = useSelect ( ( select ) => {
115+ if ( ! setupFlowRefreshEnabled || ! setupFlowRefreshPhase4Enabled ) {
116+ return false ;
117+ }
118+
119+ const internalServerError =
120+ select ( CORE_SITE ) . getInternalServerError ( ) ;
121+
122+ return (
123+ ! analyticsModuleActive &&
124+ internalServerError ?. id === ANALYTICS_SETUP_ERROR
125+ ) ;
126+ } ) ;
127+
105128 const [ inProgress , setInProgress ] = useState ( false ) ;
106129
107130 const isNavigatingToReauthURL = useSelect ( ( select ) => {
@@ -140,10 +163,17 @@ export default function ActivateAnalyticsCTA( {
140163 useEffect ( ( ) => {
141164 if ( isActivating || isNavigatingToReauthURL ) {
142165 setInProgress ( true ) ;
166+ } else if ( hasActivationError ) {
167+ setInProgress ( false ) ;
143168 } else {
144169 debouncedSetInProgress ( false ) ;
145170 }
146- } , [ isActivating , isNavigatingToReauthURL , debouncedSetInProgress ] ) ;
171+ } , [
172+ isActivating ,
173+ isNavigatingToReauthURL ,
174+ debouncedSetInProgress ,
175+ hasActivationError ,
176+ ] ) ;
147177
148178 const intersectionEntry = useIntersection ( trackingRef , {
149179 threshold : 0.25 ,
@@ -160,12 +190,23 @@ export default function ActivateAnalyticsCTA( {
160190 } , [ inView , hasBeenInView , trackEvents , analyticsEventLabel ] ) ;
161191
162192 const { dismissItem } = useDispatch ( CORE_USER ) ;
193+ const { clearInternalServerError } = useDispatch ( CORE_SITE ) ;
163194
164195 function handleDismiss ( ) {
165196 trackEvents . dismiss ( analyticsEventLabel ) ;
166197 dismissItem ( dismissedItemSlug ) ;
167198 }
168199
200+ function handleActivationRetry ( ) {
201+ clearInternalServerError ( ) ;
202+ activateModuleCallback ( ) ;
203+ trackEvents . confirm ( analyticsEventLabel ) ;
204+ }
205+
206+ function handleActivationErrorDismiss ( ) {
207+ clearInternalServerError ( ) ;
208+ }
209+
169210 const onClickCallback = analyticsModuleActive
170211 ? completeModuleActivationCallback
171212 : activateModuleCallback ;
@@ -208,6 +249,49 @@ export default function ActivateAnalyticsCTA( {
208249 ) ;
209250 }
210251
252+ if ( hasActivationError ) {
253+ return (
254+ < div
255+ className = "googlesitekit-activate-analytics-cta googlesitekit-activate-analytics-cta--error"
256+ ref = { trackingRef }
257+ >
258+ < div >
259+ < Typography
260+ type = { TYPE_LABEL }
261+ size = { SIZE_MEDIUM }
262+ as = "h2"
263+ className = "googlesitekit-activate-analytics-cta__title"
264+ >
265+ { __ ( 'Analytics setup failed' , 'google-site-kit' ) }
266+ </ Typography >
267+ < P className = "googlesitekit-activate-analytics-cta__description" >
268+ { __ (
269+ 'Something went wrong, please try again' ,
270+ 'google-site-kit'
271+ ) }
272+ </ P >
273+ </ div >
274+ < div className = "googlesitekit-activate-analytics-cta__actions" >
275+ < Button
276+ className = "googlesitekit-activate-analytics-cta__button--secondary googlesitekit-activate-analytics-cta__dismiss-button--error"
277+ onClick = { handleActivationErrorDismiss }
278+ tertiary
279+ >
280+ { __ ( 'Got it' , 'google-site-kit' ) }
281+ </ Button >
282+ < SpinnerButton
283+ className = "googlesitekit-activate-analytics-cta__button--primary"
284+ onClick = { handleActivationRetry }
285+ isSaving = { inProgress }
286+ disabled = { inProgress }
287+ >
288+ { __ ( 'Retry Analytics setup' , 'google-site-kit' ) }
289+ </ SpinnerButton >
290+ </ div >
291+ </ div >
292+ ) ;
293+ }
294+
211295 return (
212296 < div
213297 className = "googlesitekit-activate-analytics-cta"
0 commit comments