From 30f8c3914a3d0b3d3007e7c639e08fb6b56f8898 Mon Sep 17 00:00:00 2001 From: yashmantri Date: Tue, 9 Jul 2024 15:15:02 +0530 Subject: [PATCH] TP-72939 | Ms clarity added --- App.tsx | 19 ++++++++++--------- src/common/TrackingComponent.tsx | 11 ++++++++--- src/screens/auth/AuthRouter.tsx | 23 +++++++++++++++++------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/App.tsx b/App.tsx index 63d33dfb..95695f02 100644 --- a/App.tsx +++ b/App.tsx @@ -26,7 +26,7 @@ import { } from '@components/utlis/commonFunctions'; import { linkingConf } from '@components/utlis/deeplinkingUtils'; import { getBuildFlavour } from '@components/utlis/DeviceUtils'; -import { setGlobalBuildFlavour } from '@constants/Global'; +import { GLOBAL, setGlobalBuildFlavour } from '@constants/Global'; import analytics from '@react-native-firebase/analytics'; import dayJs from 'dayjs'; import { COLORS } from './RN-UI-LIB/src/styles/colors'; @@ -51,14 +51,6 @@ import { initialize, setCurrentScreenName } from 'react-native-clarity'; initSentry(); -if (ENV === 'prod') { - getAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, true).then((value) => { - if (MS_CLARITY_PROJECT_ID && value) { - initialize(MS_CLARITY_PROJECT_ID); - } - }); -} - setJsErrorHandler(); LogBox.ignoreAllLogs(); @@ -155,6 +147,15 @@ 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(); }; diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index 00491a0e..ab7f8323 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -104,7 +104,6 @@ const TrackingComponent: React.FC = ({ children }) => { const pendingList = useAppSelector((state) => state.allCases.pendingList); const pinnedList = useAppSelector((state) => state.allCases.pinnedList); - const handleTimeSync = async () => { try { if (!isOnline) { @@ -379,8 +378,14 @@ const TrackingComponent: React.FC = ({ children }) => { dispatch(getConfigData()); CosmosForegroundService.start(tasks); resyncFirebase(); - const msClarityResponse = await getLitmusExperimentResult(LitmusExperimentNameMap[LitmusExperimentName.MS_CLARITY], { 'x-customer-id': GLOBAL.AGENT_ID }); - const dataSyncResponse = await getLitmusExperimentResult(LitmusExperimentNameMap[LitmusExperimentName.COSMOS_DATA_SYNC], { 'x-customer-id': GLOBAL.AGENT_ID }); + const msClarityResponse = await getLitmusExperimentResult( + LitmusExperimentNameMap[LitmusExperimentName.MS_CLARITY], + { 'x-customer-id': GLOBAL.AGENT_ID, deviceId: GLOBAL.DEVICE_ID } + ); + const dataSyncResponse = await getLitmusExperimentResult( + LitmusExperimentNameMap[LitmusExperimentName.COSMOS_DATA_SYNC], + { 'x-customer-id': GLOBAL.AGENT_ID } + ); setAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, msClarityResponse); setAsyncStorageItem(LocalStorageKeys.IS_DATA_SYNC_ALLOWED, dataSyncResponse); diff --git a/src/screens/auth/AuthRouter.tsx b/src/screens/auth/AuthRouter.tsx index 43fc16e8..bec07c40 100644 --- a/src/screens/auth/AuthRouter.tsx +++ b/src/screens/auth/AuthRouter.tsx @@ -4,7 +4,12 @@ import { getUniqueId, isTablet } from 'react-native-device-info'; import { useAppDispatch, useAppSelector } from '../../hooks'; import { type RootState } from '../../store/store'; import { setAgentAttendance, setDeviceId } from '../../reducer/userSlice'; -import { DEVICE_TYPE_ENUM, GLOBAL, setGlobalUserData, setMsClarityConfig } from '../../constants/Global'; +import { + DEVICE_TYPE_ENUM, + GLOBAL, + setGlobalUserData, + setMsClarityConfig, +} from '../../constants/Global'; import { registerNavigateAndDispatch } from '../../components/utlis/apiHelper'; import ProtectedRouter from './ProtectedRouter'; import useNativeButtons from '../../hooks/useNativeButton'; @@ -126,11 +131,6 @@ function AuthRouter() { CosmosForegroundService.stopAll(); } }); - getLitmusExperimentResult(LitmusExperimentNameMap[LitmusExperimentName.MS_CLARITY], { - 'x-customer-id': GLOBAL.AGENT_ID, - }).then((response) => { - setAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, response); - }); getLitmusExperimentResult(LitmusExperimentNameMap[LitmusExperimentName.COSMOS_DATA_SYNC], { 'x-customer-id': GLOBAL.AGENT_ID, }).then((response) => { @@ -139,6 +139,17 @@ function AuthRouter() { } }, [isLoggedIn]); + useEffect(() => { + if (GLOBAL.DEVICE_ID) { + getLitmusExperimentResult(LitmusExperimentNameMap[LitmusExperimentName.MS_CLARITY], { + 'x-customer-id': GLOBAL.AGENT_ID, + deviceId: GLOBAL.DEVICE_ID, + }).then((response) => { + setAsyncStorageItem(LocalStorageKeys.IS_CLARITY_ENABLED, response); + }); + } + }, [GLOBAL.DEVICE_ID]); + // Firebase cloud messaging listener useFCM(); useScreenshotTracking();