diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index 4553fc54..37bd1c0b 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -182,10 +182,13 @@ public class MainApplication extends Application implements ReactApplication, Ap return; } Map anrEventProperties = new HashMap<>(); - anrEventProperties.put(SCREEN_NAME, BuildConfig.APP_NAME); + String screenName = BuildConfig.APP_NAME + "_ANR_CRASH"; + anrEventProperties.put(SCREEN_NAME, screenName); anrEventProperties.put(METHOD_NAME, error.getCause().getStackTrace()[0].getMethodName()); anrEventProperties.put(LINE_NUMBER, String.valueOf(error.getCause().getStackTrace()[0].getLineNumber())); anrEventProperties.put(APP_IN_FOREGROUND, String.valueOf(isAppInForeground())); + anrEventProperties.put("isNae", "true"); + anrEventProperties.put("errorTitle", "Something went wrong"); if (isAlfredEnabledFromFirebase && AlfredManager.INSTANCE.isAlfredRecordingEnabled() && alfredConfig.getAnrEnableStatus() && isAppInForeground()) { @@ -209,11 +212,13 @@ public class MainApplication extends Application implements ReactApplication, Ap } try { Map crashEventProperties = new HashMap<>(); - crashEventProperties.put(SCREEN_NAME, BuildConfig.APP_NAME); + String screenName = BuildConfig.APP_NAME + "_NATIVE_CRASH"; + crashEventProperties.put(SCREEN_NAME, screenName); crashEventProperties.put(METHOD_NAME, exception.getStackTrace()[0].getMethodName()); crashEventProperties.put(LINE_NUMBER, String.valueOf(exception.getStackTrace()[0].getLineNumber())); crashEventProperties.put(APP_IN_FOREGROUND, String.valueOf(isAppInForeground())); - + crashEventProperties.put("isNae", "true"); + crashEventProperties.put("errorTitle", "Something went wrong"); if (isAlfredEnabledFromFirebase && AlfredManager.INSTANCE.isAlfredRecordingEnabled() && alfredConfig.getCrashEnableStatus() && isAppInForeground()) { StackTraceElement stackTraceElement = exception.getStackTrace()[0]; diff --git a/buildFlavor/field/buildNumber.txt b/buildFlavor/field/buildNumber.txt index 10b0c0db..2b930fc4 100644 --- a/buildFlavor/field/buildNumber.txt +++ b/buildFlavor/field/buildNumber.txt @@ -1 +1 @@ -264 +265 diff --git a/buildFlavor/field/buildVersion.txt b/buildFlavor/field/buildVersion.txt index 21be78bd..417faf23 100644 --- a/buildFlavor/field/buildVersion.txt +++ b/buildFlavor/field/buildVersion.txt @@ -1 +1 @@ -2.19.5 +2.19.6 diff --git a/src/common/Constants.ts b/src/common/Constants.ts index 0bd4d345..613eb893 100644 --- a/src/common/Constants.ts +++ b/src/common/Constants.ts @@ -3,6 +3,8 @@ import { API_URLS, ApiKeys, getApiUrl } from '../components/utlis/apiHelper'; import { CaseStatuses } from '../screens/allCases/interface'; export const APP_NAME = 'collections-agent-app'; +export const SOURCE = 'SyncEventTask'; +export const COLLECTIONS_FIELD = 'COLLECTIONS_FIELD'; export enum CONDITIONAL_OPERATORS { EQUALS = 'EQUALS', diff --git a/src/common/ErrorBoundary.tsx b/src/common/ErrorBoundary.tsx index f2878803..6e34ef46 100644 --- a/src/common/ErrorBoundary.tsx +++ b/src/common/ErrorBoundary.tsx @@ -1,7 +1,7 @@ import React, { Component, ReactNode } from 'react'; import { sentryCaptureException } from '../components/utlis/errorUtils'; import { Pressable, StyleSheet, View } from 'react-native'; -import { addClickstreamEvent } from '../services/clickstreamEventService'; +import { addClickstreamEvent, handleNegativeClickstreamEvent } from '../services/clickstreamEventService'; import { CLICKSTREAM_EVENT_NAMES } from './Constants'; import ErrorImage from '../assets/images/Error'; import Heading from '../../RN-UI-LIB/src/components/Heading'; @@ -34,10 +34,11 @@ class ErrorBoundary extends Component { this.setState({ hasError: true, }); - addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_ERROR_PAGE_LOADED, { + handleNegativeClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_ERROR_PAGE_LOADED, { error, errorMessageStack: error?.stack, message: error?.message, + screen: `${getCurrentScreen()?.name}_JS_CRASH`, }); sentryCaptureException(error); crashlytics().recordError(error); diff --git a/src/components/utlis/apiHelper.ts b/src/components/utlis/apiHelper.ts index fb44755e..8874192c 100644 --- a/src/components/utlis/apiHelper.ts +++ b/src/components/utlis/apiHelper.ts @@ -292,7 +292,7 @@ export function getApiUrl( return `${apiUrl}`; } // status code to be retried on -const errorsToRetry = [500, 503]; +const errorsToRetry = [503, 504]; const axiosInstance = axios.create({ timeout: API_TIMEOUT_INTERVAL }); @@ -384,10 +384,7 @@ axiosInstance.interceptors.response.use( type: 'error', }); } - addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_API_FAILED, { - statusCode: response?.status, - url: response?.config?.url, - }); + const donotHandleErrorOnStatusCode = (config.headers.donotHandleErrorOnStatusCode || []).map( Number ); diff --git a/src/services/clickstreamEventService.ts b/src/services/clickstreamEventService.ts index ba142c6a..7bef1d84 100644 --- a/src/services/clickstreamEventService.ts +++ b/src/services/clickstreamEventService.ts @@ -11,11 +11,12 @@ import { NetInfoState, NetInfoStateType, } from '@react-native-community/netinfo'; -import { APP_NAME, DISABLE_API_EVENTS_URL } from '../common/Constants'; +import { APP_NAME, COLLECTIONS_FIELD, DISABLE_API_EVENTS_URL, SOURCE } from '../common/Constants'; import { JANUS_SERVICE_URL } from '../constants/config'; import { getBatteryLevel } from 'react-native-device-info'; import { getItem } from '@components/utlis/storageHelper'; import { SCREEN_HEIGHT, SCREEN_WIDTH } from '@rn-ui-lib/styles'; +import { getCurrentScreen } from '@components/utlis/navigationUtlis'; export type ClickstreamDesc = { name: string; description: string }; @@ -60,12 +61,26 @@ const addEvent = async (networkStatus: string) => { } }; +export const handleNegativeClickstreamEvent = ( + eventDesc: ClickstreamDesc, + attributes: Record = {}, + fireInstantly: boolean = false +) => { + const eventAttributes = { + ...attributes, + isNae: true, + errorTitle: 'Something went wrong', + }; + addClickstreamEvent(eventDesc, eventAttributes, fireInstantly); +}; + export const addClickstreamEvent = async ( eventDesc: ClickstreamDesc, attributes: Record = {}, fireInstantly: boolean = false ) => { const { DEVICE_ID: deviceId, AGENT_ID: agentId, IS_IMPERSONATED } = GLOBAL; + const {isNae = false} = attributes || {}; if (IS_IMPERSONATED || __DEV__) { // Disabled clickstream tracking for impersonated users and in dev mode return; @@ -81,8 +96,16 @@ export const addClickstreamEvent = async ( batteryLevel: batteryLevel ? String(batteryLevel * 100) : 'error', height: SCREEN_HEIGHT, width: SCREEN_WIDTH, + session_id: agentId || (await getItem('agentId')), + vertical: COLLECTIONS_FIELD, + screen: getCurrentScreen()?.params?.screen || getCurrentScreen()?.name, + ...(!isNae && { isScreenLandEvent: true }), + }; + const eventAttributes = { + ...defaultAttributes, + ...attributes, + createdAt: Date.now(), }; - const eventAttributes = { ...attributes, ...defaultAttributes, createdAt: Date.now() }; const eventDetails = { event_name: name, description, @@ -116,7 +139,7 @@ const getPayload = async (events: IClickstreamEvent[]) => { device_id: deviceId || (await getItem('deviceId')), }, client_ts: new Date().getTime(), - source: APP_NAME, + source: SOURCE, user: { customer_id: agentId || (await getItem('agentId')), }, @@ -156,16 +179,21 @@ export const sendApiToClickstreamEvent = ( } if (apiKey && DISABLE_API_EVENTS_URL.indexOf(apiKey) === -1) { const eventName = getEventNameFromAPIKey(apiKey, isSuccess); - addClickstreamEvent( - { name: eventName, description: eventName }, - { - timeTaken: milliseconds, - statusCode, - method, - endpoint: API_URLS[apiKey as keyof typeof API_URLS], - response: statusCode === 400 ? response : '', - } - ); + const eventDetails = { name: eventName, description: eventName }; + const attributesData = { + timeTaken: milliseconds, + statusCode, + method, + endpoint: API_URLS[apiKey as keyof typeof API_URLS], + response: statusCode === 400 ? response : '', + screen: `${apiKey}_API_${method}`, + }; + + if (isSuccess) { + addClickstreamEvent(eventDetails, attributesData); + } else { + handleNegativeClickstreamEvent(eventDetails, attributesData); + } } } };