2023-06-06 07:20:34 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { getSetting } from '@woocommerce/settings';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
CoreProfilerStateMachineContext,
|
|
|
|
UserProfileEvent,
|
|
|
|
BusinessInfoEvent,
|
2023-06-13 22:03:03 +00:00
|
|
|
PluginsLearnMoreLinkClicked,
|
2023-06-15 20:37:14 +00:00
|
|
|
PluginsInstallationCompletedWithErrorsEvent,
|
|
|
|
PluginsInstallationCompletedEvent,
|
2023-08-17 14:34:52 +00:00
|
|
|
PluginsInstallationRequestedEvent,
|
2023-06-06 07:20:34 +00:00
|
|
|
} from '..';
|
|
|
|
import { POSSIBLY_DEFAULT_STORE_NAMES } from '../pages/BusinessInfo';
|
2023-06-15 20:37:14 +00:00
|
|
|
import {
|
|
|
|
InstalledPlugin,
|
|
|
|
PluginInstallError,
|
|
|
|
} from '../services/installAndActivatePlugins';
|
|
|
|
import { getPluginTrackKey, getTimeFrame } from '~/utils';
|
2023-06-06 07:20:34 +00:00
|
|
|
|
|
|
|
const recordTracksStepViewed = (
|
|
|
|
_context: unknown,
|
|
|
|
_event: unknown,
|
|
|
|
{ action }: { action: unknown }
|
|
|
|
) => {
|
|
|
|
const { step } = action as { step: string };
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_step_view', {
|
2023-06-06 07:20:34 +00:00
|
|
|
step,
|
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const recordTracksStepSkipped = (
|
|
|
|
_context: unknown,
|
|
|
|
_event: unknown,
|
|
|
|
{ action }: { action: unknown }
|
|
|
|
) => {
|
|
|
|
const { step } = action as { step: string };
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( `coreprofiler_${ step }_skip` );
|
2023-06-06 07:20:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const recordTracksIntroCompleted = () => {
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_step_complete', {
|
|
|
|
step: 'intro_opt_in',
|
2023-06-06 07:20:34 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const recordTracksUserProfileCompleted = (
|
|
|
|
_context: CoreProfilerStateMachineContext,
|
|
|
|
event: Extract< UserProfileEvent, { type: 'USER_PROFILE_COMPLETED' } >
|
|
|
|
) => {
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_step_complete', {
|
2023-06-06 07:20:34 +00:00
|
|
|
step: 'user_profile',
|
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
|
|
|
} );
|
|
|
|
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_user_profile', {
|
2023-06-06 07:20:34 +00:00
|
|
|
business_choice: event.payload.userProfile.businessChoice,
|
|
|
|
selling_online_answer: event.payload.userProfile.sellingOnlineAnswer,
|
|
|
|
selling_platforms: event.payload.userProfile.sellingPlatforms
|
|
|
|
? event.payload.userProfile.sellingPlatforms.join()
|
|
|
|
: null,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
const recordTracksSkipBusinessLocationCompleted = () => {
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_step_complete', {
|
2023-06-06 07:20:34 +00:00
|
|
|
step: 'skip_business_location',
|
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-10-24 15:07:26 +00:00
|
|
|
const recordTracksIsEmailChanged = (
|
|
|
|
context: CoreProfilerStateMachineContext,
|
|
|
|
event: BusinessInfoEvent
|
|
|
|
) => {
|
2023-11-21 10:50:39 +00:00
|
|
|
let emailSource, isEmailChanged;
|
|
|
|
if ( context.onboardingProfile.store_email ) {
|
|
|
|
emailSource = 'onboarding_profile_store_email'; // from previous entry
|
|
|
|
isEmailChanged =
|
|
|
|
event.payload.storeEmailAddress !==
|
|
|
|
context.onboardingProfile.store_email;
|
|
|
|
} else if ( context.currentUserEmail ) {
|
|
|
|
emailSource = 'current_user_email'; // from currentUser
|
|
|
|
isEmailChanged =
|
|
|
|
event.payload.storeEmailAddress !== context.currentUserEmail;
|
|
|
|
} else {
|
|
|
|
emailSource = 'was_empty';
|
|
|
|
isEmailChanged = event.payload.storeEmailAddress?.length > 0;
|
2023-10-24 15:07:26 +00:00
|
|
|
}
|
2023-11-21 10:50:39 +00:00
|
|
|
|
|
|
|
recordEvent( 'coreprofiler_email_marketing', {
|
|
|
|
opt_in: event.payload.isOptInMarketing,
|
|
|
|
email_field_prefilled_source: emailSource,
|
|
|
|
email_field_modified: isEmailChanged,
|
2023-11-21 11:08:00 +00:00
|
|
|
} );
|
2023-10-24 15:07:26 +00:00
|
|
|
};
|
|
|
|
|
2023-06-06 07:20:34 +00:00
|
|
|
const recordTracksBusinessInfoCompleted = (
|
2023-10-24 15:07:26 +00:00
|
|
|
context: CoreProfilerStateMachineContext,
|
2023-06-06 07:20:34 +00:00
|
|
|
event: Extract< BusinessInfoEvent, { type: 'BUSINESS_INFO_COMPLETED' } >
|
|
|
|
) => {
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_step_complete', {
|
2023-06-06 07:20:34 +00:00
|
|
|
step: 'business_info',
|
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
|
|
|
} );
|
|
|
|
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_business_info', {
|
2023-06-06 07:20:34 +00:00
|
|
|
business_name_filled:
|
|
|
|
POSSIBLY_DEFAULT_STORE_NAMES.findIndex(
|
|
|
|
( name ) => name === event.payload.storeName
|
|
|
|
) === -1,
|
|
|
|
industry: event.payload.industry,
|
|
|
|
store_location_previously_set:
|
2023-10-24 15:07:26 +00:00
|
|
|
context.onboardingProfile.is_store_country_set || false,
|
|
|
|
geolocation_success: context.geolocatedLocation !== undefined,
|
2023-06-06 07:20:34 +00:00
|
|
|
geolocation_overruled: event.payload.geolocationOverruled,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-08-17 14:34:52 +00:00
|
|
|
const recordTracksPluginsInstallationRequest = (
|
|
|
|
_context: CoreProfilerStateMachineContext,
|
|
|
|
event: Extract<
|
|
|
|
PluginsInstallationRequestedEvent,
|
|
|
|
{ type: 'PLUGINS_INSTALLATION_REQUESTED' }
|
|
|
|
>
|
|
|
|
) => {
|
|
|
|
recordEvent( 'coreprofiler_store_extensions_continue', {
|
|
|
|
shown: event.payload.pluginsShown || [],
|
|
|
|
selected: event.payload.pluginsSelected || [],
|
|
|
|
unselected: event.payload.pluginsUnselected || [],
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-06-13 22:03:03 +00:00
|
|
|
const recordTracksPluginsLearnMoreLinkClicked = (
|
|
|
|
_context: unknown,
|
|
|
|
_event: PluginsLearnMoreLinkClicked,
|
|
|
|
{ action }: { action: unknown }
|
|
|
|
) => {
|
|
|
|
const { step } = action as { step: string };
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( `coreprofiler_${ step }_learn_more_link_clicked`, {
|
2023-06-13 22:03:03 +00:00
|
|
|
plugin: _event.payload.plugin,
|
|
|
|
link: _event.payload.learnMoreLink,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2023-06-15 20:37:14 +00:00
|
|
|
const recordFailedPluginInstallations = (
|
|
|
|
_context: unknown,
|
|
|
|
_event: PluginsInstallationCompletedWithErrorsEvent
|
|
|
|
) => {
|
2024-01-10 03:48:34 +00:00
|
|
|
const failedExtensions = _event.payload.errors.map(
|
|
|
|
( error: PluginInstallError ) => getPluginTrackKey( error.plugin )
|
|
|
|
);
|
|
|
|
|
2023-06-15 20:37:14 +00:00
|
|
|
recordEvent( 'coreprofiler_store_extensions_installed_and_activated', {
|
|
|
|
success: false,
|
2024-01-10 03:48:34 +00:00
|
|
|
failed_extensions: failedExtensions,
|
|
|
|
} );
|
|
|
|
|
|
|
|
_event.payload.errors.forEach( ( error: PluginInstallError ) => {
|
|
|
|
recordEvent( 'coreprofiler_store_extension_installed_and_activated', {
|
|
|
|
success: false,
|
|
|
|
extension: getPluginTrackKey( error.plugin ),
|
|
|
|
error_message: error.error,
|
|
|
|
} );
|
2023-06-15 20:37:14 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
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 ) {
|
2024-01-10 03:48:34 +00:00
|
|
|
const pluginKey = getPluginTrackKey( installedPlugin.plugin );
|
|
|
|
const installTime = getTimeFrame( installedPlugin.installTime );
|
|
|
|
trackData[ 'install_time_' + pluginKey ] = installTime;
|
|
|
|
|
|
|
|
recordEvent( 'coreprofiler_store_extension_installed_and_activated', {
|
|
|
|
success: true,
|
|
|
|
extension: pluginKey,
|
|
|
|
install_time: installTime,
|
|
|
|
} );
|
2023-06-15 20:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recordEvent(
|
|
|
|
'coreprofiler_store_extensions_installed_and_activated',
|
|
|
|
trackData
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-06-06 07:20:34 +00:00
|
|
|
export default {
|
|
|
|
recordTracksStepViewed,
|
|
|
|
recordTracksStepSkipped,
|
|
|
|
recordTracksIntroCompleted,
|
|
|
|
recordTracksUserProfileCompleted,
|
|
|
|
recordTracksSkipBusinessLocationCompleted,
|
|
|
|
recordTracksBusinessInfoCompleted,
|
2023-06-13 22:03:03 +00:00
|
|
|
recordTracksPluginsLearnMoreLinkClicked,
|
2023-06-15 20:37:14 +00:00
|
|
|
recordFailedPluginInstallations,
|
|
|
|
recordSuccessfulPluginInstallation,
|
2023-08-17 14:34:52 +00:00
|
|
|
recordTracksPluginsInstallationRequest,
|
2023-10-24 15:07:26 +00:00
|
|
|
recordTracksIsEmailChanged,
|
2023-06-06 07:20:34 +00:00
|
|
|
};
|