From 1edecf1afd3ff525f4dd7501bfbbc75855b2808f Mon Sep 17 00:00:00 2001 From: Rudraprasad Das Date: Wed, 4 Dec 2024 22:13:31 +0800 Subject: [PATCH] fix: fixing usage pulse for anon user (#37940) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - For usage pulse we need pageId - URL contains basePageId - basePageId needs to be converted to pageId - The conversion needs application data to be populated into redux - The PR adds a wait for application to initialise first before sending the usage pulse Fixes [37904](https://github.com/appsmithorg/appsmith/issues/37904) ## Automation /ok-to-test tags="@tag.All" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: b4c4df19b3dbea128ca63f243cdfbb14c01aa33f > Cypress dashboard. > Tags: `@tag.All` > Spec: >
Wed, 04 Dec 2024 11:40:43 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **New Features** - Enhanced user navigation tracking with improved handling of route changes. - Introduced a new function for managing user activity tracking, improving clarity and control flow. - **Bug Fixes** - Improved error handling during route changes to ensure proper logging. - **Refactor** - Restructured user-related sagas for better organization and separation of concerns. --- app/client/src/ce/sagas/NavigationSagas.ts | 11 ++++++-- app/client/src/ce/sagas/userSagas.tsx | 30 +++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) 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);