diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index dd0e2ea2a..034f22a81 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -39,6 +39,7 @@ import { MAX_RETRIES_SITE_GEN } from '../../../../constants'; import { ACTION_ONBOARDING_CHAPTER_COMPLETE, ACTION_ONBOARDING_CHAPTER_STARTED, + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, ACTION_PAGEVIEW, } from '../../../utils/analytics/hiive/constants'; import { SITEGEN_FLOW } from '../../../data/flows/constants'; @@ -179,6 +180,16 @@ const SiteGen = () => { return prevState; } ); + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + identifier, + { + source: SITEGEN_FLOW, + } + ) + ); + if ( siteGenErrorStatus === false ) { updateSiteGenErrorStatus( true ); setIsGeneratingSiteMeta( false ); @@ -217,6 +228,15 @@ const SiteGen = () => { ); if ( response.error ) { + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'homepages', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); setIsGeneratingHomepages( false ); setCurrentOnboardingData( currentData ); diff --git a/src/OnboardingSPA/components/StateHandlers/SiteGen/index.js b/src/OnboardingSPA/components/StateHandlers/SiteGen/index.js index 1d4eb579e..96cd4ed5d 100644 --- a/src/OnboardingSPA/components/StateHandlers/SiteGen/index.js +++ b/src/OnboardingSPA/components/StateHandlers/SiteGen/index.js @@ -1,20 +1,14 @@ // WordPress -import { Fragment, useEffect } from '@wordpress/element'; +import { Fragment } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; // Classes and functions -import { - OnboardingEvent, - trackOnboardingEvent, -} from '../../../utils/analytics/hiive'; // Components import SiteGenStepErrorState from '../../ErrorState/Step/SiteGen'; // Misc import { store as nfdOnboardingStore } from '../../../store'; -import { ACTION_SITEGEN_ERROR_STATE_TRIGGERED } from '../../../utils/analytics/hiive/constants'; -import { SITEGEN_FLOW } from '../../../data/flows/constants'; const SiteGenStateHandler = ( { children } ) => { const { siteGenErrorStatus } = useSelect( ( select ) => { @@ -25,20 +19,6 @@ const SiteGenStateHandler = ( { children } ) => { }; } ); - useEffect( () => { - if ( true === siteGenErrorStatus ) { - trackOnboardingEvent( - new OnboardingEvent( - ACTION_SITEGEN_ERROR_STATE_TRIGGERED, - undefined, - { - source: SITEGEN_FLOW, - } - ) - ); - } - }, [ siteGenErrorStatus ] ); - const handleRender = () => { if ( siteGenErrorStatus ) { return ; diff --git a/src/OnboardingSPA/steps/SiteGen/Migration/index.js b/src/OnboardingSPA/steps/SiteGen/Migration/index.js index f4381e655..18bed6976 100644 --- a/src/OnboardingSPA/steps/SiteGen/Migration/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Migration/index.js @@ -18,7 +18,12 @@ import { stepWelcome } from '../../GetStarted/Welcome/step'; import { injectMigrationStep } from '../../../data/flows/utils'; import { store as nfdOnboardingStore } from '../../../store'; import { FOOTER_SITEGEN, HEADER_SITEGEN } from '../../../../constants'; +import { + OnboardingEvent, + trackOnboardingEvent, +} from '../../../utils/analytics/hiive'; import { SITEGEN_FLOW } from '../../../data/flows/constants'; +import { ACTION_SITEGEN_ERROR_STATE_TRIGGERED } from '../../../utils/analytics/hiive/constants'; const StepSiteGenMigration = () => { const { @@ -57,14 +62,41 @@ const StepSiteGenMigration = () => { window.open( migrateUrl, '_self' ); }, 3000 ); } else { + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'migration', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); } } else { + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'migration', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); } } catch ( error ) { // eslint-disable-next-line no-console console.error( 'Failed to fetch migration URL:', error ); + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'migration', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); } }; diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index 312dc4148..d83b405be 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -29,6 +29,7 @@ import { // Misc import { + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, ACTION_SITEGEN_HOMEPAGE_FAVORITED, ACTION_SITEGEN_HOMEPAGE_REGENERATED, ACTION_SITEGEN_HOMEPAGE_SELECTED, @@ -112,6 +113,15 @@ const SiteGenPreview = () => { if ( response.error ) { setIsPreviewLoading( false ); + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'homepages', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); return; } diff --git a/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js b/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js index 6dcce1e95..6d68061c1 100644 --- a/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js +++ b/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js @@ -23,6 +23,7 @@ import { store as nfdOnboardingStore } from '../../../store'; import { HEADER_SITEGEN } from '../../../../constants'; import { ACTION_LOGO_ADDED, + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, ACTION_SITEGEN_LOGO_SKIPPED, } from '../../../utils/analytics/hiive/constants'; import { SITEGEN_FLOW } from '../../../data/flows/constants'; @@ -105,6 +106,15 @@ const SiteGenSiteLogo = () => { }; const handleFailure = () => { + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'site-logo', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); }; diff --git a/src/OnboardingSPA/steps/SiteGen/SocialMedia/index.js b/src/OnboardingSPA/steps/SiteGen/SocialMedia/index.js index c9e7a627f..cffd8362b 100644 --- a/src/OnboardingSPA/steps/SiteGen/SocialMedia/index.js +++ b/src/OnboardingSPA/steps/SiteGen/SocialMedia/index.js @@ -25,6 +25,7 @@ import { SiteGenStateHandler } from '../../../components/StateHandlers'; import { store as nfdOnboardingStore } from '../../../store'; import { HEADER_SITEGEN } from '../../../../constants'; import { + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, ACTION_SITEGEN_SOCIAL_CONNECTED, ACTION_SITEGEN_SOCIAL_CONNECT_SKIPPED, } from '../../../utils/analytics/hiive/constants'; @@ -83,6 +84,15 @@ const SiteGenSiteSocialMedia = () => { if ( 404 === error?.data?.status ) { return; } + trackOnboardingEvent( + new OnboardingEvent( + ACTION_SITEGEN_ERROR_STATE_TRIGGERED, + 'social-media', + { + source: SITEGEN_FLOW, + } + ) + ); updateSiteGenErrorStatus( true ); }; diff --git a/src/OnboardingSPA/utils/analytics/hiive/constants.js b/src/OnboardingSPA/utils/analytics/hiive/constants.js index c563f4c35..21157f837 100644 --- a/src/OnboardingSPA/utils/analytics/hiive/constants.js +++ b/src/OnboardingSPA/utils/analytics/hiive/constants.js @@ -66,4 +66,5 @@ export const ACTION_TO_LABEL_KEY_MAP = { [ ACTION_SITEGEN_HOMEPAGE_RENAMED ]: 'version', [ ACTION_SITEGEN_SITE_GENERATION_TIME ]: 'time', [ ACTION_MIGRATION_INITIATED ]: 'path', + [ ACTION_SITEGEN_ERROR_STATE_TRIGGERED ]: 'identifier', };