From 5694d12ee1381a5ca987fbc74c5d52318bd6bd76 Mon Sep 17 00:00:00 2001 From: Prajjaval Verma Date: Thu, 5 Dec 2024 16:59:28 +0530 Subject: [PATCH] NTP-17879 | GI NAP Phase 2 Changes (#13975) --- .../Navi-Insurance/network/BenefitPageApi.ts | 3 +++ .../network/MarketBenefitComparePageApi.ts | 3 +++ .../Navi-Insurance/network/QuotePageApi.ts | 10 +++++++++- .../Navi-Insurance/network/WaitingPeriodApi.ts | 3 +++ App/common/constants/BuildConfigConstants.ts | 8 ++++++++ App/common/hooks/useAnalyticsEvent.ts | 8 ++++++++ App/common/interface/analytics/GlobalErrorData.ts | 3 +++ App/common/screen/ScreenActionHandler.tsx | 5 +++++ .../widgets/widget-actions/WidgetActionHandler.ts | 10 +++++++++- .../connectors/NativeAnalyticsConnector.kt | 10 ++++++---- .../repository/PaymentReviewRepository.kt | 7 +++++-- .../autopayoption/viewmodel/PaymentReviewVM.kt | 14 +++++++++++++- .../journey/ui/PreQuoteJourneyViewModel.kt | 2 +- 13 files changed, 76 insertions(+), 10 deletions(-) diff --git a/App/Container/Navi-Insurance/network/BenefitPageApi.ts b/App/Container/Navi-Insurance/network/BenefitPageApi.ts index 0afc269c86..b1699555e0 100644 --- a/App/Container/Navi-Insurance/network/BenefitPageApi.ts +++ b/App/Container/Navi-Insurance/network/BenefitPageApi.ts @@ -6,6 +6,7 @@ import { AnalyticsEventNameConstants, AnalyticsFlowNameConstant, AnalyticsMethodNameConstant, + ApiMethod, GI, } from "../../../common/constants"; import { sendAsAnalyticsEvent } from "../../../common/hooks/useAnalyticsEvent"; @@ -62,6 +63,8 @@ export const getBenefitPageData = async ( AnalyticsFlowNameConstant.GI_RN_BENEFIT, AnalyticsMethodNameConstant.FETCH_BENEFIT_LIST, startTime, + url, + ApiMethod.GET, ); isScreenLoaded = true; } else { diff --git a/App/Container/Navi-Insurance/network/MarketBenefitComparePageApi.ts b/App/Container/Navi-Insurance/network/MarketBenefitComparePageApi.ts index b2cd06c494..dc1f40433a 100644 --- a/App/Container/Navi-Insurance/network/MarketBenefitComparePageApi.ts +++ b/App/Container/Navi-Insurance/network/MarketBenefitComparePageApi.ts @@ -6,6 +6,7 @@ import { AnalyticsEventNameConstants, AnalyticsFlowNameConstant, AnalyticsMethodNameConstant, + ApiMethod, GI, } from "../../../common/constants"; import { sendAsAnalyticsEvent } from "../../../common/hooks/useAnalyticsEvent"; @@ -58,6 +59,8 @@ export const getMarketBenefitComparePageData = async ( AnalyticsFlowNameConstant.GI_RN_BENEFIT_COMPARE, AnalyticsMethodNameConstant.MARKET_BENEFIT_COMPARE_LIST, startTime, + url, + ApiMethod.GET, ); isScreenLoaded = true; } else { diff --git a/App/Container/Navi-Insurance/network/QuotePageApi.ts b/App/Container/Navi-Insurance/network/QuotePageApi.ts index 4ae80150e8..4e0216a02c 100644 --- a/App/Container/Navi-Insurance/network/QuotePageApi.ts +++ b/App/Container/Navi-Insurance/network/QuotePageApi.ts @@ -7,6 +7,7 @@ import { ActionMetaData } from "../../../common/actions/GenericAction"; import { AnalyticsFlowNameConstant, AnalyticsMethodNameConstant, + ApiMethod, BASE_SCREEN, } from "../../../common/constants"; import { GI } from "../../../common/constants/NavigationHandlerConstants"; @@ -68,6 +69,8 @@ export const createQuote = async ( AnalyticsFlowNameConstant.GI_RN_QUOTE, AnalyticsMethodNameConstant.FETCH_QUOTE_V4, startTime, + url, + ApiMethod.POST, ); }); }; @@ -103,6 +106,8 @@ export const getQuotePageData = async ( AnalyticsFlowNameConstant.GI_RN_QUOTE, AnalyticsMethodNameConstant.FETCH_INSURANCE_QUOTE_PAGE_FROM_BACKEND, startTime, + url, + ApiMethod.GET, ); }); }; @@ -124,8 +129,9 @@ export const fetchComparisonPlanList = async ( setScreenData: Dispatch>, ) => { const startTime = Date.now(); + const url = "quotes/compare-plans"; return post>( - "quotes/compare-plans", + url, screenMetaData.data, getXTargetHeaderInfo(GI.toLocaleUpperCase()), ) @@ -144,6 +150,8 @@ export const fetchComparisonPlanList = async ( AnalyticsFlowNameConstant.GI_RN_QUOTE, AnalyticsMethodNameConstant.COMPARE_PLAN_LIST, startTime, + url, + ApiMethod.POST, ); }); }; diff --git a/App/Container/Navi-Insurance/network/WaitingPeriodApi.ts b/App/Container/Navi-Insurance/network/WaitingPeriodApi.ts index da29f12363..0b834aff61 100644 --- a/App/Container/Navi-Insurance/network/WaitingPeriodApi.ts +++ b/App/Container/Navi-Insurance/network/WaitingPeriodApi.ts @@ -6,6 +6,7 @@ import { AnalyticsEventNameConstants, AnalyticsFlowNameConstant, AnalyticsMethodNameConstant, + ApiMethod, GI, } from "../../../common/constants"; import { sendAsAnalyticsEvent } from "../../../common/hooks/useAnalyticsEvent"; @@ -58,6 +59,8 @@ export const getWaitingPeriodScreenData = async ( AnalyticsFlowNameConstant.GI_WAITING_PERIOD, AnalyticsMethodNameConstant.WAITING_PERIOD_SCREEN, startTime, + url, + ApiMethod.GET, ); isScreenLoaded = true; } else { diff --git a/App/common/constants/BuildConfigConstants.ts b/App/common/constants/BuildConfigConstants.ts index e9aff69bb5..5b6855667e 100644 --- a/App/common/constants/BuildConfigConstants.ts +++ b/App/common/constants/BuildConfigConstants.ts @@ -4,3 +4,11 @@ export enum BuildConfigConstants { APP_VERSION_CODE = "appVersionCode", FLAVOR = "flavor", } + +export const ApiMethod = { + POST: "POST", + GET: "GET", + PUT: "PUT", + DELETE: "DELETE", + PATCH: "PATCH", +}; diff --git a/App/common/hooks/useAnalyticsEvent.ts b/App/common/hooks/useAnalyticsEvent.ts index 8a7e954efd..90a2b469da 100644 --- a/App/common/hooks/useAnalyticsEvent.ts +++ b/App/common/hooks/useAnalyticsEvent.ts @@ -4,6 +4,7 @@ import { EVENT_PROPERTY_KEYS, REACT_NATIVE } from "../constants"; import { AnalyticsEvent } from "../interface"; import { NativeAnalyticsModule } from "../native-module/NativeModules"; import { ScreenState } from "../screen/BaseScreen"; +import { BASE_URL } from "../../../network/NetworkConstant"; export const useAnalyticsEvent = () => { return { @@ -74,9 +75,13 @@ export const sendAsGlobalErrorEvent = (event: GlobalErrorData) => { errorCode = null, errorTitle = null, latency = null, + isNae = null, + apiUrl = null, + apiMethod = null, } = event; const updatedSource = moduleName + "_" + REACT_NATIVE + "_" + source; + const updatedApiUrl = BASE_URL + apiUrl; NativeAnalyticsModule.sendAsGlobalErrorEvent({ reason, @@ -94,6 +99,9 @@ export const sendAsGlobalErrorEvent = (event: GlobalErrorData) => { errorCode, errorTitle, latency, + isNae, + apiUrl: updatedApiUrl, + apiMethod, }); }; diff --git a/App/common/interface/analytics/GlobalErrorData.ts b/App/common/interface/analytics/GlobalErrorData.ts index 5f5b239050..0ef42a346b 100644 --- a/App/common/interface/analytics/GlobalErrorData.ts +++ b/App/common/interface/analytics/GlobalErrorData.ts @@ -14,4 +14,7 @@ interface GlobalErrorData { latency?: number | null; errorCode?: string | null; errorTitle?: string | null; + isNae?: boolean | null; + apiUrl?: string | null; + apiMethod?: string | null; } diff --git a/App/common/screen/ScreenActionHandler.tsx b/App/common/screen/ScreenActionHandler.tsx index d65a6a3013..28b030dec4 100644 --- a/App/common/screen/ScreenActionHandler.tsx +++ b/App/common/screen/ScreenActionHandler.tsx @@ -83,6 +83,8 @@ export const handleErrorData = ( flowName: string, methodName: string, startTime: number, + apiUrl: string, + apiMethod: string, ) => { sendAsAnalyticsEvent({ name: AnalyticsEventNameConstants.HI_RN_INVALID_DATA_ERROR, @@ -105,6 +107,9 @@ export const handleErrorData = ( errorCode: error.axiosCode, errorTitle: getErrorTitleFromError(error.statusCode || -1), latency: latency, + isNae: error.statusCode === 20 ? false : true, + apiUrl: apiUrl, + apiMethod: apiMethod, }; sendAsGlobalErrorEvent(errorEvent); const updatedScreenData: ScreenData = { diff --git a/App/common/widgets/widget-actions/WidgetActionHandler.ts b/App/common/widgets/widget-actions/WidgetActionHandler.ts index 174e5e2d7c..7a38868539 100644 --- a/App/common/widgets/widget-actions/WidgetActionHandler.ts +++ b/App/common/widgets/widget-actions/WidgetActionHandler.ts @@ -8,6 +8,7 @@ import { GenericActionPayload, TargetWidgetPayload, } from "../../actions/GenericAction"; +import { ApiMethod } from "../../constants"; import { AnalyticsEventNameConstants, AnalyticsFlowNameConstant, @@ -34,7 +35,6 @@ import { getErrorTypeFromStatusCode } from "../../utilities/ErrorUtils"; import { updateValueByKeyPath } from "../../utilities/MiscUtils"; import { parseValue } from "../../utilities/SerializerUtil"; import { WidgetActionTypes } from "./WidgetActionTypes"; -import { BASE_SCREEN } from "../../constants"; const WidgetActionHandler = { handleWidgetAction: ( @@ -172,6 +172,7 @@ const WidgetActionHandler = { widgetMetaData?.data as FinalPatchCallRequestBody ).nextPageCta; requestData.applicationId = applicationId; + const url = `v3/quotes/${quoteId}`; return updateSumInsuredData(requestData, quoteId!!) .then(response => { handleResponseData(nextPageCta, setScreenData, screenData); @@ -183,6 +184,8 @@ const WidgetActionHandler = { widgetMetaData, AnalyticsMethodNameConstant.FINAL_PATCH_CALL, screenData, + url, + ApiMethod.PATCH, ); }); } @@ -278,6 +281,8 @@ const handleErrorData = ( widgetMetaData: ActionMetaData, methodName: string, screenData?: ScreenData | null, + apiUrl?: string, + apiMethod?: string, ) => { sendAsAnalyticsEvent({ name: AnalyticsEventNameConstants.HI_RN_INVALID_DATA_ERROR, @@ -296,6 +301,9 @@ const handleErrorData = ( methodName: methodName, globalErrorType: getErrorTypeFromStatusCode(error.statusCode || -1), isAppDowntimeEvent: false, + isNae: false, + apiUrl: apiUrl, + apiMethod: apiMethod, }; sendAsGlobalErrorEvent(errorEvent); setScreenData({ diff --git a/android/app/src/main/java/com/naviapp/react_native/native_bridge/connectors/NativeAnalyticsConnector.kt b/android/app/src/main/java/com/naviapp/react_native/native_bridge/connectors/NativeAnalyticsConnector.kt index e96f2f3709..fbb3970f3e 100644 --- a/android/app/src/main/java/com/naviapp/react_native/native_bridge/connectors/NativeAnalyticsConnector.kt +++ b/android/app/src/main/java/com/naviapp/react_native/native_bridge/connectors/NativeAnalyticsConnector.kt @@ -11,7 +11,6 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableMap -import com.navi.base.utils.EMPTY import com.navi.base.utils.orFalse import com.navi.base.utils.orZero import com.navi.common.checkmate.core.CheckMateManager @@ -105,17 +104,20 @@ class NativeAnalyticsConnector internal constructor(context: ReactApplicationCon val latency = (propsMap["latency"] as? Double)?.toLong() ?: 0L val errorCode = propsMap["errorCode"] as? String val errorTitle = propsMap["errorTitle"] as? String + val isNae = propsMap["isNae"] as? Boolean ?: true + val apiUrl = propsMap["apiUrl"] as? String + val apiMethod = propsMap["apiMethod"] as? String CheckMateManager.recordNetworkEvent( statusCode = statusCode?.toInt().orZero(), actualLatency = latency.orZero(), networkLatency = latency.orZero(), - isNae = statusCode?.toInt() != 20, + isNae = isNae, httpStatusCode = statusCode?.toInt().orZero(), vertical = getModuleNameForCheckMate(moduleName), screen = source.orEmpty(), - method = EMPTY, - endpoint = methodName.orEmpty(), + method = apiMethod.orEmpty(), + endpoint = apiUrl.orEmpty(), errorCode = errorCode.orEmpty(), errorTitle = errorTitle.orEmpty(), errorDes = reason.orEmpty(), diff --git a/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/repository/PaymentReviewRepository.kt b/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/repository/PaymentReviewRepository.kt index b76e5a89e0..897ab8bf9d 100644 --- a/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/repository/PaymentReviewRepository.kt +++ b/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/repository/PaymentReviewRepository.kt @@ -7,6 +7,7 @@ package com.navi.insurance.paymentreview.autopayoption.repository +import com.navi.common.checkmate.model.MetricInfo import com.navi.common.network.models.RepoResult import com.navi.common.network.retrofit.ResponseCallback import com.navi.insurance.models.response.PaymentReviewResponse @@ -19,13 +20,15 @@ class PaymentReviewRepository @Inject constructor(private val retrofitService: R suspend fun fetchPaymentReviewInMR( id: String? = null, paymentFlowIdentifier: String?, - applicationId: String? = null + applicationId: String? = null, + metricInfo: MetricInfo>? = null ): RepoResult = apiResponseCallback( retrofitService.fetchPAymentReviewInMR( id = id, paymentFlowIdentifier, applicationId = applicationId - ) + ), + metricInfo ) } diff --git a/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/viewmodel/PaymentReviewVM.kt b/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/viewmodel/PaymentReviewVM.kt index 2a4998b45d..4bab896bca 100644 --- a/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/viewmodel/PaymentReviewVM.kt +++ b/android/navi-insurance/src/main/java/com/navi/insurance/paymentreview/autopayoption/viewmodel/PaymentReviewVM.kt @@ -12,7 +12,9 @@ import com.navi.base.model.CtaData import com.navi.base.utils.isNotNull import com.navi.base.utils.isNull import com.navi.common.ResponseState +import com.navi.common.checkmate.model.MetricInfo import com.navi.common.di.CoroutineDispatcherProvider +import com.navi.common.network.models.isSuccessWithData import com.navi.insurance.common.models.GiErrorMetaData import com.navi.insurance.common.util.ActionHandler import com.navi.insurance.models.response.PaymentReviewResponse @@ -70,8 +72,18 @@ constructor( dispatcher.io + exceptionHandler(ApiErrorTagType.PAYMENT_REVIEW_SCREEN_LOAD_ERROR.value) ) { _paymentRequestFlow.value = ResponseState.Loading + val metricInfo = + MetricInfo.InsuranceMetricInfo( + screen = "paymentReviewScreen", + isNae = { !it.isSuccessWithData() } + ) val response = - repository.fetchPaymentReviewInMR(id, paymentFlowIdentifier, applicationId) + repository.fetchPaymentReviewInMR( + id, + paymentFlowIdentifier, + applicationId, + metricInfo + ) if ( response.error.isNull() && response.errors.isNullOrEmpty() && diff --git a/android/navi-insurance/src/main/java/com/navi/insurance/pre/purchase/journey/ui/PreQuoteJourneyViewModel.kt b/android/navi-insurance/src/main/java/com/navi/insurance/pre/purchase/journey/ui/PreQuoteJourneyViewModel.kt index 08e62006b5..1eabf7e05a 100644 --- a/android/navi-insurance/src/main/java/com/navi/insurance/pre/purchase/journey/ui/PreQuoteJourneyViewModel.kt +++ b/android/navi-insurance/src/main/java/com/navi/insurance/pre/purchase/journey/ui/PreQuoteJourneyViewModel.kt @@ -365,7 +365,7 @@ constructor( ) { val metricInfo = MetricInfo.InsuranceMetricInfo( - screen = "PreQuoteJourneyViewModel", + screen = "PreQuoteJourney", isNae = { !it.isSuccessWithData() && it.statusCode != ERROR_CODE_400 } ) val response =