one-click-accessibility/assets/dev/js/services/mixpanel/mixpanel-props/migration.js
matviy-yermakov 11f70e78c1
[APP-2894] - Changed target name being "move to one" or "not now" | Added interaction result "skip_migration" (#567)
* APP-2894 One Migration flow: Move Accessibillity to One

* Added mixpanel events for one_migration_popup_displayed and one_migration_button_clicked actions

* Removed X icon for the migration popup
2026-06-25 10:29:20 +02:00

84 lines
2.4 KiB
JavaScript

import { mixpanelEvents } from '../mixpanel-events';
const MIGRATION_APP_TYPE = 'app_access';
const MIGRATION_APP_NAME = 'accessibility';
const ONE_MIGRATION_POPUP_DISPLAYED_PROPS = {
app_type: MIGRATION_APP_TYPE,
window_name: 'app_shell',
interaction_type: 'impression',
target_type: 'popup',
target_name: 'one_migration',
interaction_result: 'popup_displayed',
target_location: 'app_page',
interaction_desc:
'One migration popup is shown to a user who has both an active One subscription and a standalone app subscription',
metadata: [`app_name: ${MIGRATION_APP_NAME}`],
};
const MIGRATION_TARGET_NAMES = {
move_to_one: 'move to one',
not_now: 'not now',
};
/**
* @param {'move_to_one' | 'not_now'} button
* @param {'migration_success' | 'migration_failed' | 'skip_migration'} interactionResult
* @param {'success' | 'failed' | null} [status]
* @param {string} [error]
*/
const buildOneMigrationButtonClickedProps = (
button,
interactionResult,
status = null,
error,
) => {
const metadata = [`status: ${status}`];
if (error) {
metadata.push(`error: ${error}`);
}
return {
app_type: MIGRATION_APP_TYPE,
window_name: 'app_shell',
interaction_type: 'click',
target_type: 'button',
target_name: MIGRATION_TARGET_NAMES[button],
interaction_result: interactionResult,
target_location: 'one_migration_popup',
interaction_desc:
'User clicks Move to One or Not now on the One migration popup; if Move to One, result reflects API outcome',
metadata,
};
};
/**
* @param {Function} sendEvent
*/
export const createOneMigrationTracking = (sendEvent) => ({
trackPopupDisplayed: () => {
sendEvent(
mixpanelEvents.oneMigrationPopupDisplayed,
ONE_MIGRATION_POPUP_DISPLAYED_PROPS,
);
},
/**
* @param {'move_to_one' | 'not_now'} button
* @param {'migration_success' | 'migration_failed' | 'skip_migration'} interactionResult
* @param {'success' | 'failed' | null} [status]
* @param {string} [error]
*/
trackButtonClicked: (button, interactionResult, status = null, error) => {
sendEvent(
mixpanelEvents.oneMigrationButtonClicked,
buildOneMigrationButtonClickedProps(
button,
interactionResult,
status,
error,
),
);
},
});