From d51f69d2d712554a6f80de075e50a29553297ba3 Mon Sep 17 00:00:00 2001 From: Moon Date: Thu, 15 Jun 2023 13:37:14 -0700 Subject: [PATCH] Update track name prefix for core profiler (#38710) * Use coreprofiler_ prefix * Add Changelog * Track name changes * Rename intro_optin to intro_opt_in * Extracted out recordFailedPluginInstallations and recordSuccessfulPluginInstallation to tracks * Fix js lint error -- remove unused import --- .../client/core-profiler/actions/tracks.tsx | 74 ++++++++++++++++--- .../client/core-profiler/index.tsx | 72 ++---------------- ...8627-update-track-prefix-for-core-profiler | 4 + 3 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 plugins/woocommerce/changelog/update-38627-update-track-prefix-for-core-profiler diff --git a/plugins/woocommerce-admin/client/core-profiler/actions/tracks.tsx b/plugins/woocommerce-admin/client/core-profiler/actions/tracks.tsx index 944fc584ed4..9691ee441cd 100644 --- a/plugins/woocommerce-admin/client/core-profiler/actions/tracks.tsx +++ b/plugins/woocommerce-admin/client/core-profiler/actions/tracks.tsx @@ -12,8 +12,15 @@ import { UserProfileEvent, BusinessInfoEvent, PluginsLearnMoreLinkClicked, + PluginsInstallationCompletedWithErrorsEvent, + PluginsInstallationCompletedEvent, } from '..'; import { POSSIBLY_DEFAULT_STORE_NAMES } from '../pages/BusinessInfo'; +import { + InstalledPlugin, + PluginInstallError, +} from '../services/installAndActivatePlugins'; +import { getPluginTrackKey, getTimeFrame } from '~/utils'; const recordTracksStepViewed = ( _context: unknown, @@ -21,7 +28,7 @@ const recordTracksStepViewed = ( { action }: { action: unknown } ) => { const { step } = action as { step: string }; - recordEvent( 'storeprofiler_step_view', { + recordEvent( 'coreprofiler_step_view', { step, wc_version: getSetting( 'wcVersion' ), } ); @@ -33,12 +40,12 @@ const recordTracksStepSkipped = ( { action }: { action: unknown } ) => { const { step } = action as { step: string }; - recordEvent( `storeprofiler_${ step }_skip` ); + recordEvent( `coreprofiler_${ step }_skip` ); }; const recordTracksIntroCompleted = () => { - recordEvent( 'storeprofiler_step_complete', { - step: 'store_details', + recordEvent( 'coreprofiler_step_complete', { + step: 'intro_opt_in', wc_version: getSetting( 'wcVersion' ), } ); }; @@ -47,12 +54,12 @@ const recordTracksUserProfileCompleted = ( _context: CoreProfilerStateMachineContext, event: Extract< UserProfileEvent, { type: 'USER_PROFILE_COMPLETED' } > ) => { - recordEvent( 'storeprofiler_step_complete', { + recordEvent( 'coreprofiler_step_complete', { step: 'user_profile', wc_version: getSetting( 'wcVersion' ), } ); - recordEvent( 'storeprofiler_user_profile', { + recordEvent( 'coreprofiler_user_profile', { business_choice: event.payload.userProfile.businessChoice, selling_online_answer: event.payload.userProfile.sellingOnlineAnswer, selling_platforms: event.payload.userProfile.sellingPlatforms @@ -62,7 +69,7 @@ const recordTracksUserProfileCompleted = ( }; const recordTracksSkipBusinessLocationCompleted = () => { - recordEvent( 'storeprofiler_step_complete', { + recordEvent( 'coreprofiler_step_complete', { step: 'skip_business_location', wc_version: getSetting( 'wcVersion' ), } ); @@ -72,12 +79,12 @@ const recordTracksBusinessInfoCompleted = ( _context: CoreProfilerStateMachineContext, event: Extract< BusinessInfoEvent, { type: 'BUSINESS_INFO_COMPLETED' } > ) => { - recordEvent( 'storeprofiler_step_complete', { + recordEvent( 'coreprofiler_step_complete', { step: 'business_info', wc_version: getSetting( 'wcVersion' ), } ); - recordEvent( 'storeprofiler_business_info', { + recordEvent( 'coreprofiler_business_info', { business_name_filled: POSSIBLY_DEFAULT_STORE_NAMES.findIndex( ( name ) => name === event.payload.storeName @@ -96,12 +103,57 @@ const recordTracksPluginsLearnMoreLinkClicked = ( { action }: { action: unknown } ) => { const { step } = action as { step: string }; - recordEvent( `storeprofiler_${ step }_learn_more_link_clicked`, { + recordEvent( `coreprofiler_${ step }_learn_more_link_clicked`, { plugin: _event.payload.plugin, link: _event.payload.learnMoreLink, } ); }; +const recordFailedPluginInstallations = ( + _context: unknown, + _event: PluginsInstallationCompletedWithErrorsEvent +) => { + recordEvent( 'coreprofiler_store_extensions_installed_and_activated', { + success: false, + failed_extensions: _event.payload.errors.map( + ( error: PluginInstallError ) => getPluginTrackKey( error.plugin ) + ), + } ); +}; + +const recordSuccessfulPluginInstallation = ( + _context: unknown, + _event: PluginsInstallationCompletedEvent +) => { + const installationCompletedResult = + _event.payload.installationCompletedResult; + + const trackData: { + success: boolean; + installed_extensions: string[]; + total_time: string; + [ key: string ]: number | boolean | string | string[]; + } = { + success: true, + installed_extensions: installationCompletedResult.installedPlugins.map( + ( installedPlugin: InstalledPlugin ) => + getPluginTrackKey( installedPlugin.plugin ) + ), + total_time: getTimeFrame( installationCompletedResult.totalTime ), + }; + + for ( const installedPlugin of installationCompletedResult.installedPlugins ) { + trackData[ + 'install_time_' + getPluginTrackKey( installedPlugin.plugin ) + ] = getTimeFrame( installedPlugin.installTime ); + } + + recordEvent( + 'coreprofiler_store_extensions_installed_and_activated', + trackData + ); +}; + export default { recordTracksStepViewed, recordTracksStepSkipped, @@ -110,4 +162,6 @@ export default { recordTracksSkipBusinessLocationCompleted, recordTracksBusinessInfoCompleted, recordTracksPluginsLearnMoreLinkClicked, + recordFailedPluginInstallations, + recordSuccessfulPluginInstallation, }; diff --git a/plugins/woocommerce-admin/client/core-profiler/index.tsx b/plugins/woocommerce-admin/client/core-profiler/index.tsx index ddd86412d45..69fab4f18bd 100644 --- a/plugins/woocommerce-admin/client/core-profiler/index.tsx +++ b/plugins/woocommerce-admin/client/core-profiler/index.tsx @@ -26,7 +26,6 @@ import { Extension, GeolocationResponse, } from '@woocommerce/data'; -import { recordEvent } from '@woocommerce/tracks'; import { initializeExPlat } from '@woocommerce/explat'; import { CountryStateOption } from '@woocommerce/onboarding'; @@ -49,7 +48,7 @@ import { BusinessLocation } from './pages/BusinessLocation'; import { getCountryStateOptions } from './services/country'; import { Loader } from './pages/Loader'; import { Plugins } from './pages/Plugins'; -import { getPluginSlug, getPluginTrackKey, getTimeFrame } from '~/utils'; +import { getPluginSlug } from '~/utils'; import './style.scss'; import { InstallationCompletedResult, @@ -693,7 +692,7 @@ export const coreProfilerStateMachineDefinition = createMachine( { entry: [ { type: 'recordTracksStepViewed', - step: 'store_details', + step: 'intro_opt_in', }, { type: 'updateQueryStep', step: 'intro-opt-in' }, ], @@ -709,7 +708,7 @@ export const coreProfilerStateMachineDefinition = createMachine( { actions: [ { type: 'recordTracksStepSkipped', - step: 'store_details', + step: 'intro_opt_in', }, ], }, @@ -1222,73 +1221,16 @@ export const coreProfilerStateMachineDefinition = createMachine( { event ) => event.payload.errors, } ), - ( _context, event ) => { - recordEvent( - 'storeprofiler_store_extensions_installed_and_activated', - { - success: false, - failed_extensions: - event.payload.errors.map( - ( - error: PluginInstallError - ) => - getPluginTrackKey( - error.plugin - ) - ), - } - ); + { + type: 'recordFailedPluginInstallations', }, ], }, PLUGINS_INSTALLATION_COMPLETED: { target: 'postPluginInstallation', actions: [ - ( _context, event ) => { - const installationCompletedResult = - event.payload - .installationCompletedResult; - - const trackData: { - success: boolean; - installed_extensions: string[]; - total_time: string; - [ key: string ]: - | number - | boolean - | string - | string[]; - } = { - success: true, - installed_extensions: - installationCompletedResult.installedPlugins.map( - ( - installedPlugin: InstalledPlugin - ) => - getPluginTrackKey( - installedPlugin.plugin - ) - ), - total_time: getTimeFrame( - installationCompletedResult.totalTime - ), - }; - - for ( const installedPlugin of installationCompletedResult.installedPlugins ) { - trackData[ - 'install_time_' + - getPluginTrackKey( - installedPlugin.plugin - ) - ] = getTimeFrame( - installedPlugin.installTime - ); - } - - recordEvent( - 'storeprofiler_store_extensions_installed_and_activated', - trackData - ); + { + type: 'recordSuccessfulPluginInstallation', }, ], }, diff --git a/plugins/woocommerce/changelog/update-38627-update-track-prefix-for-core-profiler b/plugins/woocommerce/changelog/update-38627-update-track-prefix-for-core-profiler new file mode 100644 index 00000000000..651979f4837 --- /dev/null +++ b/plugins/woocommerce/changelog/update-38627-update-track-prefix-for-core-profiler @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Use coreprofiler_ prefix for core profiler track names