diff --git a/app/client/src/ce/sagas/NavigationSagas.ts b/app/client/src/ce/sagas/NavigationSagas.ts index f84cd79091c..dff86d7d089 100644 --- a/app/client/src/ce/sagas/NavigationSagas.ts +++ b/app/client/src/ce/sagas/NavigationSagas.ts @@ -1,10 +1,13 @@ -import { fork, put, select, call } from "redux-saga/effects"; +import { fork, put, select, call, take } from "redux-saga/effects"; import type { RouteChangeActionPayload } from "actions/focusHistoryActions"; import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity"; import log from "loglevel"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { getRecentEntityIds } from "selectors/globalSearchSelectors"; -import type { ReduxAction } from "ee/constants/ReduxActionConstants"; +import { + ReduxActionTypes, + type ReduxAction, +} from "ee/constants/ReduxActionConstants"; import { getCurrentThemeDetails } from "selectors/themeSelectors"; import type { BackgroundTheme } from "sagas/ThemeSaga"; import { changeAppBackground } from "sagas/ThemeSaga"; @@ -86,6 +89,10 @@ function* clearErrors() { } function* watchForTrackableUrl(payload: RouteChangeActionPayload) { + yield take([ + ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS, + ReduxActionTypes.INITIALIZE_PAGE_VIEWER_SUCCESS, + ]); const oldPathname = payload.prevLocation.pathname; const newPathname = payload.location.pathname; const isOldPathTrackable: boolean = yield call( diff --git a/app/client/src/ce/sagas/userSagas.tsx b/app/client/src/ce/sagas/userSagas.tsx index 132341739bb..34e229fea2c 100644 --- a/app/client/src/ce/sagas/userSagas.tsx +++ b/app/client/src/ce/sagas/userSagas.tsx @@ -145,15 +145,11 @@ function* initTrackers(currentUser: User) { } } -export function* runUserSideEffectsSaga() { +function* restartUserTracking() { const currentUser: User = yield select(getCurrentUser); const { enableTelemetry } = currentUser; const isAirgappedInstance = isAirgapped(); - if (enableTelemetry) { - yield fork(initTrackers, currentUser); - } - const isFFFetched: boolean = yield select(getFeatureFlagsFetched); if (!isFFFetched) { @@ -169,13 +165,33 @@ export function* runUserSideEffectsSaga() { if (!isAirgappedInstance) { // We need to stop and start tracking activity to ensure that the tracking from previous session is not carried forward - UsagePulse.stopTrackingActivity(); - UsagePulse.startTrackingActivity( + yield call(UsagePulse.stopTrackingActivity); + + if (currentUser?.isAnonymous) { + yield take([ + ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS, + ReduxActionTypes.INITIALIZE_PAGE_VIEWER_SUCCESS, + ]); + } + + yield call( + UsagePulse.startTrackingActivity, enableTelemetry && getAppsmithConfigs().segment.enabled, currentUser?.isAnonymous ?? false, isFreeLicense, ); } +} + +export function* runUserSideEffectsSaga() { + const currentUser: User = yield select(getCurrentUser); + const { enableTelemetry } = currentUser; + + if (enableTelemetry) { + yield fork(initTrackers, currentUser); + } + + yield fork(restartUserTracking); if (currentUser.emptyInstance) { history.replace(SETUP);