Skip to content

Commit

Permalink
Merge pull request #37952 from appsmithorg/chore/usage-pulse-cherry-pick
Browse files Browse the repository at this point in the history
fix: fixing usage pulse for anon user (#37940)
  • Loading branch information
btsgh authored Dec 5, 2024
2 parents 8d910dd + 1edecf1 commit 7930bec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
11 changes: 9 additions & 2 deletions app/client/src/ce/sagas/NavigationSagas.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand Down
30 changes: 23 additions & 7 deletions app/client/src/ce/sagas/userSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 7930bec

Please sign in to comment.