From 81a7245efd9894baa0c074e1a221275c8c8d2441 Mon Sep 17 00:00:00 2001 From: Prajjaval Verma Date: Thu, 5 Sep 2024 21:49:32 +0530 Subject: [PATCH] TP-79757 | ScreenName in RN error events (#12314) --- .../screen/compare-plan-screen/ComparePlanScreen.tsx | 3 ++- .../MarketBenefitCompareScreen.tsx | 2 ++ .../screen/quote-offer-screen/QuoteOfferScreen.tsx | 4 +++- App/common/actions/GenericAction.ts | 1 + App/common/constants/StringConstant.ts | 1 + App/common/hooks/useAnalyticsEvent.ts | 10 +++++++--- App/common/screen/ScreenActionHandler.tsx | 6 ++++-- App/common/utilities/ErrorUtils.ts | 12 ++++++++++++ .../widgets/widget-actions/WidgetActionHandler.ts | 6 ++++-- 9 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 App/common/utilities/ErrorUtils.ts diff --git a/App/Container/Navi-Insurance/screen/compare-plan-screen/ComparePlanScreen.tsx b/App/Container/Navi-Insurance/screen/compare-plan-screen/ComparePlanScreen.tsx index 57e3f757cd..ecf7fd8dbf 100644 --- a/App/Container/Navi-Insurance/screen/compare-plan-screen/ComparePlanScreen.tsx +++ b/App/Container/Navi-Insurance/screen/compare-plan-screen/ComparePlanScreen.tsx @@ -19,7 +19,7 @@ import { extractCtaParameters, } from "../../../../common/navigator/NavigationRouter"; import QuoteOfferErrorScreen from "../quote-offer-screen/error-screen/QuoteOfferErrorScreen"; -import { ConstantCta } from "../../../../common/constants"; +import { COMPARE_PLAN_SCREEN, ConstantCta } from "../../../../common/constants"; const ComparePlanScreen = ({ ctaData, @@ -71,6 +71,7 @@ const ComparePlanScreen = ({ { actionType: ScreenActionTypes.FETCH_COMPARE_PLAN_LIST, data: ctaData?.data, + screenName: COMPARE_PLAN_SCREEN }, ], }); diff --git a/App/Container/Navi-Insurance/screen/market-benefit-compare-screen/MarketBenefitCompareScreen.tsx b/App/Container/Navi-Insurance/screen/market-benefit-compare-screen/MarketBenefitCompareScreen.tsx index dab0f0d926..d87bbc1a79 100644 --- a/App/Container/Navi-Insurance/screen/market-benefit-compare-screen/MarketBenefitCompareScreen.tsx +++ b/App/Container/Navi-Insurance/screen/market-benefit-compare-screen/MarketBenefitCompareScreen.tsx @@ -18,6 +18,7 @@ import { import { AnalyticsEventNameConstants, ConstantCta, + MARKET_BENEFITS_COMPARE_SCREEN, } from "../../../../common/constants"; import { sendAsAnalyticsEvent } from "../../../../common/hooks/useAnalyticsEvent"; import { logToSentry } from "../../../../common/hooks/useSentryLogging"; @@ -96,6 +97,7 @@ const MarketBenefitCompareScreen = ({ { actionType: ScreenActionTypes.FETCH_BENEFIT_COMPARE_LIST, data: ctaData?.data, + screenName: MARKET_BENEFITS_COMPARE_SCREEN }, ], }); diff --git a/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx b/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx index 2002d28123..a9f4b64e1d 100644 --- a/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx +++ b/App/Container/Navi-Insurance/screen/quote-offer-screen/QuoteOfferScreen.tsx @@ -22,7 +22,7 @@ import { BaseActionTypes, GenericActionPayload, } from "../../../../common/actions/GenericAction"; -import { ConstantCta, ScreenProperties } from "../../../../common/constants"; +import { ConstantCta, QUOTE_OFFER_SCREEN, ScreenProperties } from "../../../../common/constants"; import { AnalyticsEventNameConstants } from "../../../../common/constants/AnalyticsEventsConstant"; import { NativeEventNameConstants } from "../../../../common/constants/EventNameConstants"; import { @@ -179,6 +179,7 @@ const QuoteOfferScreen = ({ { actionType: screenActionType, data: data, + screenName: QUOTE_OFFER_SCREEN }, ], }); @@ -203,6 +204,7 @@ const QuoteOfferScreen = ({ { actionType: screenActionType, data: data, + screenName: QUOTE_OFFER_SCREEN }, ], }); diff --git a/App/common/actions/GenericAction.ts b/App/common/actions/GenericAction.ts index a628ee0674..9d610e22ec 100644 --- a/App/common/actions/GenericAction.ts +++ b/App/common/actions/GenericAction.ts @@ -19,6 +19,7 @@ export interface ActionMetaData { // ActionMetaData has some key attributes required to perform any action e.g. critical widget communications i.e. inter/intra widget, screen level API calls, bottom sheet, modal, etc. data?: any; analyticsEventProperties?: AnalyticsEvent; + screenName?: string; } export interface TargetWidgetPayload { diff --git a/App/common/constants/StringConstant.ts b/App/common/constants/StringConstant.ts index 0fb8edfff5..35240e8656 100644 --- a/App/common/constants/StringConstant.ts +++ b/App/common/constants/StringConstant.ts @@ -44,3 +44,4 @@ export const QUOTE_PATCH_FAIL_TOAST = "Failed. Try again"; export const QUOTE_ID = "quoteId"; export const BUILD_CONFIG_DETAILS = "BUILD_CONFIG_DETAILS"; export const SPACE_UNICODE = "\u00A0"; +export const REACT_NATIVE = 'rn' diff --git a/App/common/hooks/useAnalyticsEvent.ts b/App/common/hooks/useAnalyticsEvent.ts index b42cc4afff..e76921ef2e 100644 --- a/App/common/hooks/useAnalyticsEvent.ts +++ b/App/common/hooks/useAnalyticsEvent.ts @@ -1,5 +1,5 @@ import { getBundleVersion } from "../../../network/NetworkUtils"; -import { EVENT_PROPERTY_KEYS } from "../constants"; +import { EVENT_PROPERTY_KEYS, REACT_NATIVE } from "../constants"; import { AnalyticsEvent } from "../interface"; import { NativeAnalyticsModule } from "../native-module/NativeModules"; @@ -37,9 +37,11 @@ export const sendAsAppDowntimeEvent = (event: AppDowntimeData) => { eventName = "global_app_downtime", } = event; + const updatedScreenName = moduleName + "_" + REACT_NATIVE + "_" + screenName; + NativeAnalyticsModule.sendAsAppDowntimeEvent({ reason, - screenName, + screenName: updatedScreenName, moduleName, statusCode, networkType, @@ -67,9 +69,11 @@ export const sendAsGlobalErrorEvent = (event: GlobalErrorData) => { isAppDowntimeEvent = null, } = event; + const updatedSource = moduleName + "_" + REACT_NATIVE + "_" + source; + NativeAnalyticsModule.sendAsGlobalErrorEvent({ reason, - source, + source: updatedSource, moduleName, globalErrorType, statusCode, diff --git a/App/common/screen/ScreenActionHandler.tsx b/App/common/screen/ScreenActionHandler.tsx index 1ebf4c6993..aaf406afa5 100644 --- a/App/common/screen/ScreenActionHandler.tsx +++ b/App/common/screen/ScreenActionHandler.tsx @@ -23,6 +23,7 @@ import { CtaData } from "../interface"; import { ScreenData } from "../interface/widgets/screenData/ScreenData"; import { ScreenState } from "./BaseScreen"; import { ScreenActionTypes } from "./ScreenActionTypes"; +import { getErrorTypeFromStatusCode } from "../utilities/ErrorUtils"; export const ScreenActionHandler = { handleScreenAction: ( @@ -212,12 +213,13 @@ const handleErrorData = ( ); const errorEvent: GlobalErrorData = { reason: `${error.message}, axiosError: ${error.axiosCode}`, + source: screenMetaData.screenName || "", statusCode: error.statusCode, moduleName: AnalyticsModuleNameConstant.GI, flowName: AnalyticsFlowNameConstant.GI_RN_QUOTE, methodName: methodName, - globalErrorType: AnalyticsGlobalErrorTypeConstant.GLOBAL_INTERNAL_ERRORS, - isAppDowntimeEvent: true, + globalErrorType: getErrorTypeFromStatusCode(error.statusCode || -1), + isAppDowntimeEvent: false, }; sendAsGlobalErrorEvent(errorEvent); const updatedScreenData: ScreenData = { diff --git a/App/common/utilities/ErrorUtils.ts b/App/common/utilities/ErrorUtils.ts new file mode 100644 index 0000000000..141dd5dd2a --- /dev/null +++ b/App/common/utilities/ErrorUtils.ts @@ -0,0 +1,12 @@ +import { AnalyticsGlobalErrorTypeConstant } from "../constants"; + +export const getErrorTypeFromStatusCode = (statusCode: number) => { + const statusCodeforGenericError = [20, 23, 24, 401, 404]; + + if (statusCodeforGenericError.includes(statusCode) || statusCode >= 500) { + return AnalyticsGlobalErrorTypeConstant.GLOBAL_GENERIC_ERRORS; + } + + return AnalyticsGlobalErrorTypeConstant.GLOBAL_INTERNAL_ERRORS; +}; + \ No newline at end of file diff --git a/App/common/widgets/widget-actions/WidgetActionHandler.ts b/App/common/widgets/widget-actions/WidgetActionHandler.ts index ddc57f6894..6cae2fd8b1 100644 --- a/App/common/widgets/widget-actions/WidgetActionHandler.ts +++ b/App/common/widgets/widget-actions/WidgetActionHandler.ts @@ -32,6 +32,7 @@ import { import { updateValueByKeyPath } from "../../utilities/MiscUtils"; import { parseValue } from "../../utilities/SerializerUtil"; import { WidgetActionTypes } from "./WidgetActionTypes"; +import { getErrorTypeFromStatusCode } from "../../utilities/ErrorUtils"; const WidgetActionHandler = { handleWidgetAction: ( @@ -273,12 +274,13 @@ const handleErrorData = ( ); const errorEvent: GlobalErrorData = { reason: `${error.message}, axiosError: ${error.axiosCode}`, + source: widgetMetaData.screenName || "", statusCode: error.statusCode, moduleName: AnalyticsModuleNameConstant.GI, flowName: AnalyticsFlowNameConstant.GI_RN_QUOTE, methodName: methodName, - globalErrorType: AnalyticsGlobalErrorTypeConstant.GLOBAL_INTERNAL_ERRORS, - isAppDowntimeEvent: true, + globalErrorType: getErrorTypeFromStatusCode(error.statusCode || -1), + isAppDowntimeEvent: false, }; sendAsGlobalErrorEvent(errorEvent); setScreenData({