From c75501d9524093f421ea2d3f26cc937484f1e063 Mon Sep 17 00:00:00 2001 From: Alka Date: Mon, 30 Oct 2023 18:06:16 +0530 Subject: [PATCH] feat(INJI-433): add events for VC share success and failure scenario for sender Signed-off-by: Alka --- machines/bleShare/request/requestMachine.ts | 5 +- machines/bleShare/scan/scanMachine.ts | 103 ++++++++++++++++---- screens/Scan/SendVcScreen.tsx | 13 +++ shared/telemetry/TelemetryUtils.js | 4 + 4 files changed, 105 insertions(+), 20 deletions(-) diff --git a/machines/bleShare/request/requestMachine.ts b/machines/bleShare/request/requestMachine.ts index 5282ad709..3437c5428 100644 --- a/machines/bleShare/request/requestMachine.ts +++ b/machines/bleShare/request/requestMachine.ts @@ -768,7 +768,10 @@ export const requestMachine = callback({type: 'DISCONNECT'}); } - if (event.type === EventTypes.onError) { + if ( + event.type === EventTypes.onError && + event.code.includes('TVV') + ) { callback({ type: 'BLE_ERROR', bleError: {message: event.message, code: event.code}, diff --git a/machines/bleShare/scan/scanMachine.ts b/machines/bleShare/scan/scanMachine.ts index 6e1a39a4a..bf8de4bbd 100644 --- a/machines/bleShare/scan/scanMachine.ts +++ b/machines/bleShare/scan/scanMachine.ts @@ -45,6 +45,10 @@ import { sendStartEvent, sendEndEvent, TelemetryConstants, + sendImpressionEvent, + getImpressionEventData, + sendErrorEvent, + getErrorEventData, } from '../../../shared/telemetry/TelemetryUtils'; import {logState} from '../../../shared/commonUtil'; @@ -145,7 +149,7 @@ export const scanMachine = }, BLE_ERROR: { target: '.handlingBleError', - actions: 'setBleError', + actions: ['sendBLEConnectionErrorEvent', 'setBleError'], }, RESET: { target: '.checkStorage', @@ -397,12 +401,12 @@ export const scanMachine = { target: 'connecting', cond: 'isOpenIdQr', - actions: 'setUri', + actions: ['sendTelemetryStartEvent', 'setUri'], }, { target: 'showQrLogin', cond: 'isQrLogin', - actions: 'setLinkCode', + actions: ['sendTelemetryStartEvent', 'setLinkCode'], }, { target: 'invalid', @@ -504,6 +508,7 @@ export const scanMachine = }, CANCEL: { target: 'cancelling', + actions: 'sendVCShareFlowCancelEndEvent', }, TOGGLE_USER_CONSENT: { actions: 'toggleShouldVerifyPresence', @@ -537,11 +542,17 @@ export const scanMachine = }, CANCEL: { target: '#scan.reviewing.cancelling', - actions: 'setPromptHint', + actions: [ + 'setPromptHint', + 'sendVCShareFlowTimeoutEndEvent', + ], }, RETRY: { target: '#scan.reviewing.cancelling', - actions: 'setPromptHint', + actions: [ + 'setPromptHint', + 'sendVCShareFlowTimeoutEndEvent', + ], }, }, }, @@ -574,16 +585,7 @@ export const scanMachine = }, }, accepted: { - entry: [ - 'logShared', - () => - sendEndEvent( - getEndEventData( - TelemetryConstants.FlowType.vcShare, - TelemetryConstants.EndEventStatus.success, - ), - ), - ], + entry: ['logShared', 'sendVcShareSuccessEvent'], on: { DISMISS: { target: 'navigatingToHome', @@ -905,6 +907,69 @@ export const scanMachine = to: context => context.serviceRefs.activityLog, }, ), + + sendVcShareSuccessEvent: () => { + sendImpressionEvent( + getImpressionEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.Screens.vcShareSuccessPage, + ), + ); + sendEndEvent( + getEndEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.EndEventStatus.success, + ), + ); + }, + + sendBLEConnectionErrorEvent: (context, event) => { + sendErrorEvent( + getErrorEventData( + TelemetryConstants.FlowType.vcShare, + event.bleError.code, + event.bleError.message, + ), + ); + sendEndEvent( + getEndEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.EndEventStatus.failure, + ), + ); + }, + + sendTelemetryStartEvent: () => { + sendStartEvent( + getStartEventData(TelemetryConstants.FlowType.vcShare), + ); + sendImpressionEvent( + getImpressionEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.Screens.scanScreen, + ), + ); + }, + + sendVCShareFlowCancelEndEvent: () => { + sendEndEvent( + getEndEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.EndEventStatus.cancel, + {comment: 'User cancelled VC share'}, + ), + ); + }, + + sendVCShareFlowTimeoutEndEvent: () => { + sendEndEvent( + getEndEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.EndEventStatus.failure, + {comment: 'VC sharing timeout'}, + ), + ); + }, }, services: { @@ -958,7 +1023,10 @@ export const scanMachine = if (event.type === EventTypes.onDisconnected) { callback({type: 'DISCONNECT'}); } - if (event.type === EventTypes.onError) { + if ( + event.type === EventTypes.onError && + event.code.includes('TVW') + ) { callback({ type: 'BLE_ERROR', bleError: {message: event.message, code: event.code}, @@ -1022,9 +1090,6 @@ export const scanMachine = }, startConnection: context => callback => { - sendStartEvent( - getStartEventData(TelemetryConstants.FlowType.vcShare), - ); wallet.startConnection(context.openId4VpUri); const statusCallback = (event: WalletDataEvent) => { if (event.type === EventTypes.onSecureChannelEstablished) { diff --git a/screens/Scan/SendVcScreen.tsx b/screens/Scan/SendVcScreen.tsx index 34ea8a1c9..089521853 100644 --- a/screens/Scan/SendVcScreen.tsx +++ b/screens/Scan/SendVcScreen.tsx @@ -14,6 +14,11 @@ import {useFocusEffect} from '@react-navigation/native'; import {VcItemContainer} from '../../components/VC/VcItemContainer'; import {VCMetadata} from '../../shared/VCMetadata'; import {createEsignetMosipVCItemMachine} from '../../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine'; +import { + TelemetryConstants, + getImpressionEventData, + sendImpressionEvent, +} from '../../shared/telemetry/TelemetryUtils'; export const SendVcScreen: React.FC = () => { const {t} = useTranslation('SendVcScreen'); @@ -43,6 +48,14 @@ export const SendVcScreen: React.FC = () => { controller.SELECT_VC_ITEM(0)(service); } }, []); + useEffect(() => { + sendImpressionEvent( + getImpressionEventData( + TelemetryConstants.FlowType.vcShare, + TelemetryConstants.Screens.vcList, + ), + ); + }, []); useFocusEffect( React.useCallback(() => { diff --git a/shared/telemetry/TelemetryUtils.js b/shared/telemetry/TelemetryUtils.js index 77659a24b..be5142183 100644 --- a/shared/telemetry/TelemetryUtils.js +++ b/shared/telemetry/TelemetryUtils.js @@ -195,6 +195,7 @@ export const TelemetryConstants = { EndEventStatus: Object.freeze({ success: 'SUCCESS', + cancel: 'CANCEL', failure: 'FAILURE', }), @@ -225,5 +226,8 @@ export const TelemetryConstants = { webViewPage: 'Web View Page', otpVerificationModal: 'Otp Verification Modal', issuerList: 'Issuer List', + scanScreen: 'Scan Screen', + vcList: 'VC List', + vcShareSuccessPage: 'VC Successfully Shared Page', }), };