woocommerce/plugins/woocommerce-admin/client/core-profiler/actions/tracks.tsx

225 lines
6.3 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { getSetting } from '@woocommerce/settings';
import { recordEvent } from '@woocommerce/tracks';
/**
* Internal dependencies
*/
import { CoreProfilerStateMachineContext } from '..';
import {
UserProfileEvent,
BusinessInfoEvent,
PluginsLearnMoreLinkClickedEvent,
PluginsInstallationCompletedWithErrorsEvent,
PluginsInstallationCompletedEvent,
PluginsInstallationRequestedEvent,
} from '../events';
import { POSSIBLY_DEFAULT_STORE_NAMES } from '../pages/BusinessInfo';
import {
InstalledPlugin,
PluginInstallError,
} from '../services/installAndActivatePlugins';
import { getPluginTrackKey, getTimeFrame } from '~/utils';
const recordTracksStepViewed = ( _: unknown, params: { step: string } ) => {
recordEvent( 'coreprofiler_step_view', {
step: params.step,
wc_version: getSetting( 'wcVersion' ),
} );
};
const recordTracksStepSkipped = ( _: unknown, params: { step: string } ) => {
recordEvent( `coreprofiler_${ params.step }_skip` );
};
const recordTracksIntroCompleted = () => {
recordEvent( 'coreprofiler_step_complete', {
step: 'intro_opt_in',
wc_version: getSetting( 'wcVersion' ),
} );
};
const recordTracksUserProfileCompleted = ( {
event,
}: {
event: Extract< UserProfileEvent, { type: 'USER_PROFILE_COMPLETED' } >;
} ) => {
recordEvent( 'coreprofiler_step_complete', {
step: 'user_profile',
wc_version: getSetting( 'wcVersion' ),
} );
recordEvent( 'coreprofiler_user_profile', {
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 = () => {
recordEvent( 'coreprofiler_step_complete', {
step: 'skip_business_location',
wc_version: getSetting( 'wcVersion' ),
} );
};
const recordTracksIsEmailChanged = ( {
context,
event,
}: {
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-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
} );
};
const recordTracksBusinessInfoCompleted = ( {
context,
event,
}: {
context: CoreProfilerStateMachineContext;
event: Extract< BusinessInfoEvent, { type: 'BUSINESS_INFO_COMPLETED' } >;
} ) => {
recordEvent( 'coreprofiler_step_complete', {
step: 'business_info',
wc_version: getSetting( 'wcVersion' ),
} );
recordEvent( 'coreprofiler_business_info', {
business_name_filled:
POSSIBLY_DEFAULT_STORE_NAMES.findIndex(
( name ) => name === event.payload.storeName
) === -1,
industry: event.payload.industry,
store_location_previously_set:
context.onboardingProfile.is_store_country_set || false,
geolocation_success: context.geolocatedLocation !== undefined,
geolocation_overruled: event.payload.geolocationOverruled,
} );
};
const recordTracksPluginsInstallationRequest = ( {
event,
}: {
event: Extract<
PluginsInstallationRequestedEvent,
{ type: 'PLUGINS_INSTALLATION_REQUESTED' }
>;
} ) => {
recordEvent( 'coreprofiler_store_extensions_continue', {
shown: event.payload.pluginsShown || [],
selected: event.payload.pluginsSelected || [],
unselected: event.payload.pluginsUnselected || [],
} );
};
Additional changes for the core profiler plugins page (#38616) * Add install-and-activate-plugins-async action to onboarding * Add label and learn_more_link types * Use label and learn_more_link * Fix type * Add changelog * Add changelog * Add install_priority -- this will be used in the core profiler * Sort selected plugins by install_priority for installation * Remove unused imports * dev: refactor installAndActivatePlugins to xstate * ts fixes * Sort plugins by install_priority * Make sure WooCommerce Shipping is always visible * Update free extension list content * Updated WC payment description * Updated logo images * Visual changes on the plugin page * Change CTA font size from 13px to 14px * Change spacing between the chebox and logo to 24px * Change heading font-weight to 500 * Fix css lint error * Fix gray-900 variable name * Hide learn more link on mobile view * Add back learn more link that was removed from rebase * Send pluginsAvailable to pluginInstallermachine * Use is_activated to determine plugin availability and install status * Update packages/js/data/src/onboarding/types.ts Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Update plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Add back recordTracksPluginsLearnMoreLinkClicked * Use install-and-activate-plugins-async when timer is up * Record plugin and link with learn more linked clicked event * Fix failign tests * Add comment for install_priority --------- Co-authored-by: rjchow <me@rjchow.com> Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2023-06-13 22:03:03 +00:00
const recordTracksPluginsLearnMoreLinkClicked = (
{ event }: { event: PluginsLearnMoreLinkClickedEvent },
params: { step: string }
Additional changes for the core profiler plugins page (#38616) * Add install-and-activate-plugins-async action to onboarding * Add label and learn_more_link types * Use label and learn_more_link * Fix type * Add changelog * Add changelog * Add install_priority -- this will be used in the core profiler * Sort selected plugins by install_priority for installation * Remove unused imports * dev: refactor installAndActivatePlugins to xstate * ts fixes * Sort plugins by install_priority * Make sure WooCommerce Shipping is always visible * Update free extension list content * Updated WC payment description * Updated logo images * Visual changes on the plugin page * Change CTA font size from 13px to 14px * Change spacing between the chebox and logo to 24px * Change heading font-weight to 500 * Fix css lint error * Fix gray-900 variable name * Hide learn more link on mobile view * Add back learn more link that was removed from rebase * Send pluginsAvailable to pluginInstallermachine * Use is_activated to determine plugin availability and install status * Update packages/js/data/src/onboarding/types.ts Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Update plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Add back recordTracksPluginsLearnMoreLinkClicked * Use install-and-activate-plugins-async when timer is up * Record plugin and link with learn more linked clicked event * Fix failign tests * Add comment for install_priority --------- Co-authored-by: rjchow <me@rjchow.com> Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2023-06-13 22:03:03 +00:00
) => {
recordEvent( `coreprofiler_${ params.step }_learn_more_link_clicked`, {
plugin: event.payload.plugin,
link: event.payload.learnMoreLink,
Additional changes for the core profiler plugins page (#38616) * Add install-and-activate-plugins-async action to onboarding * Add label and learn_more_link types * Use label and learn_more_link * Fix type * Add changelog * Add changelog * Add install_priority -- this will be used in the core profiler * Sort selected plugins by install_priority for installation * Remove unused imports * dev: refactor installAndActivatePlugins to xstate * ts fixes * Sort plugins by install_priority * Make sure WooCommerce Shipping is always visible * Update free extension list content * Updated WC payment description * Updated logo images * Visual changes on the plugin page * Change CTA font size from 13px to 14px * Change spacing between the chebox and logo to 24px * Change heading font-weight to 500 * Fix css lint error * Fix gray-900 variable name * Hide learn more link on mobile view * Add back learn more link that was removed from rebase * Send pluginsAvailable to pluginInstallermachine * Use is_activated to determine plugin availability and install status * Update packages/js/data/src/onboarding/types.ts Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Update plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Add back recordTracksPluginsLearnMoreLinkClicked * Use install-and-activate-plugins-async when timer is up * Record plugin and link with learn more linked clicked event * Fix failign tests * Add comment for install_priority --------- Co-authored-by: rjchow <me@rjchow.com> Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2023-06-13 22:03:03 +00:00
} );
};
const recordFailedPluginInstallations = ( {
event,
}: {
event: PluginsInstallationCompletedWithErrorsEvent;
} ) => {
const failedExtensions = event.payload.errors.map(
( error: PluginInstallError ) => getPluginTrackKey( error.plugin )
);
recordEvent( 'coreprofiler_store_extensions_installed_and_activated', {
success: false,
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,
} );
} );
};
const recordSuccessfulPluginInstallation = ( {
event,
}: {
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 ) {
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,
} );
}
recordEvent(
'coreprofiler_store_extensions_installed_and_activated',
trackData
);
};
export default {
recordTracksStepViewed,
recordTracksStepSkipped,
recordTracksIntroCompleted,
recordTracksUserProfileCompleted,
recordTracksSkipBusinessLocationCompleted,
recordTracksBusinessInfoCompleted,
Additional changes for the core profiler plugins page (#38616) * Add install-and-activate-plugins-async action to onboarding * Add label and learn_more_link types * Use label and learn_more_link * Fix type * Add changelog * Add changelog * Add install_priority -- this will be used in the core profiler * Sort selected plugins by install_priority for installation * Remove unused imports * dev: refactor installAndActivatePlugins to xstate * ts fixes * Sort plugins by install_priority * Make sure WooCommerce Shipping is always visible * Update free extension list content * Updated WC payment description * Updated logo images * Visual changes on the plugin page * Change CTA font size from 13px to 14px * Change spacing between the chebox and logo to 24px * Change heading font-weight to 500 * Fix css lint error * Fix gray-900 variable name * Hide learn more link on mobile view * Add back learn more link that was removed from rebase * Send pluginsAvailable to pluginInstallermachine * Use is_activated to determine plugin availability and install status * Update packages/js/data/src/onboarding/types.ts Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Update plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/DefaultFreeExtensions.php Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> * Add back recordTracksPluginsLearnMoreLinkClicked * Use install-and-activate-plugins-async when timer is up * Record plugin and link with learn more linked clicked event * Fix failign tests * Add comment for install_priority --------- Co-authored-by: rjchow <me@rjchow.com> Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2023-06-13 22:03:03 +00:00
recordTracksPluginsLearnMoreLinkClicked,
recordFailedPluginInstallations,
recordSuccessfulPluginInstallation,
recordTracksPluginsInstallationRequest,
recordTracksIsEmailChanged,
};