diff --git a/App.tsx b/App.tsx index 95695f02..9be22002 100644 --- a/App.tsx +++ b/App.tsx @@ -147,20 +147,20 @@ function App() { checkCodePushAndSync(); setForegroundTimeStampAndClickstream(); - if (ENV === 'prod') { - getAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, true).then((value) => { - if (MS_CLARITY_PROJECT_ID && value && !GLOBAL.MS_CLARITY_INITIALIZED) { - initialize(MS_CLARITY_PROJECT_ID); - GLOBAL.MS_CLARITY_INITIALIZED = true; - } - }); - } - return () => { appStateChange.remove(); }; }, []); + React.useEffect(() => { + if (ENV === 'prod' && GLOBAL.IS_CLARTIY_ENABLED) { + if (MS_CLARITY_PROJECT_ID && !GLOBAL.MS_CLARITY_INITIALIZED) { + initialize(MS_CLARITY_PROJECT_ID); + GLOBAL.MS_CLARITY_INITIALIZED = true; + } + } + }, [GLOBAL.IS_CLARTIY_ENABLED]); + return ( = ({ children }) => { { 'x-customer-id': GLOBAL.AGENT_ID } ); - setAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, msClarityResponse); + GLOBAL.IS_CLARTIY_ENABLED = msClarityResponse; setAsyncStorageItem(LocalStorageKeys.IS_DATA_SYNC_ALLOWED, dataSyncResponse); } if (nextAppState === AppStates.BACKGROUND) { diff --git a/src/components/utlis/apiHelper.ts b/src/components/utlis/apiHelper.ts index 4bf30f17..5604cf20 100644 --- a/src/components/utlis/apiHelper.ts +++ b/src/components/utlis/apiHelper.ts @@ -275,7 +275,9 @@ axiosInstance.interceptors.response.use( } const { config, response } = error; setCustomTag('apiError', `API Error occured - ${response?.status}`); - alfredHandleSWWEvent(new Error("Error in Alfred recording in API response")); + if (response?.status === 403) { + alfredHandleSWWEvent(new Error('Error in Alfred recording in API response')); + } logError(error as Error, config?.baseURL + config?.url); const start = response?.config?.headers['request-start-time']; const end = Date.now(); diff --git a/src/constants/Global.ts b/src/constants/Global.ts index d8de7e9f..4bb028a0 100644 --- a/src/constants/Global.ts +++ b/src/constants/Global.ts @@ -16,6 +16,8 @@ export const GLOBAL = { IS_IMPERSONATED: false, SELECTED_AGENT_ID: '', BUILD_FLAVOUR: '', + MS_CLARITY_INITIALIZED: false, + IS_CLARTIY_ENABLED: false }; interface IGlobalUserData { diff --git a/src/screens/auth/AuthRouter.tsx b/src/screens/auth/AuthRouter.tsx index bec07c40..dd670dfe 100644 --- a/src/screens/auth/AuthRouter.tsx +++ b/src/screens/auth/AuthRouter.tsx @@ -145,7 +145,7 @@ function AuthRouter() { 'x-customer-id': GLOBAL.AGENT_ID, deviceId: GLOBAL.DEVICE_ID, }).then((response) => { - setAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, response); + GLOBAL.IS_CLARTIY_ENABLED = response; }); } }, [GLOBAL.DEVICE_ID]);