From ec1d737edc146212dad73bf5ebe4d6b4b447b4fb Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Mon, 11 Nov 2024 10:47:32 +0530 Subject: [PATCH] fix: Analytics identify user not called correctly (#37303) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Update the call sequence during init to solve for analytics issue. It was found that the `identifyUser` in analytics was not called properly when in edit mode. This change will fix the call sequence. It also ensures that the init of analytics is not a blocker by forking out the call into a different generator function ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 984e325a14e8c4f9d3a0ac87d31365728b37785e > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Fri, 08 Nov 2024 13:16:33 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit - **New Features** - Enhanced analytics tracking capabilities by integrating user identification into the analytics setup process. - Simplified the initialization of analytics trackers for improved performance. - **Bug Fixes** - Improved error handling for analytics initialization and user tracking. - **Documentation** - Updated comments for clarity regarding the new analytics tracking logic. --- app/client/src/ce/sagas/userSagas.tsx | 28 +++++++++----------------- app/client/src/utils/AppsmithUtils.tsx | 8 +++++++- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/client/src/ce/sagas/userSagas.tsx b/app/client/src/ce/sagas/userSagas.tsx index 76fdb329cc..42f5cfa837 100644 --- a/app/client/src/ce/sagas/userSagas.tsx +++ b/app/client/src/ce/sagas/userSagas.tsx @@ -43,7 +43,6 @@ import { import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { INVITE_USERS_TO_WORKSPACE_FORM } from "ee/constants/forms"; import type { User } from "constants/userConstants"; -import { ANONYMOUS_USERNAME } from "constants/userConstants"; import { flushErrorsAndRedirect, safeCrashAppRequest, @@ -190,9 +189,15 @@ export function* getCurrentUserSaga(action?: { } } -function* intializeSmartLook(currentUser: User) { - if (!currentUser.isAnonymous && currentUser.username !== ANONYMOUS_USERNAME) { - yield AnalyticsUtil.identifyUser(currentUser); +function* initTrackers(currentUser: User) { + const initializeSentry = initializeAnalyticsAndTrackers(currentUser); + + const sentryInitialized: boolean = yield initializeSentry; + + if (sentryInitialized) { + yield put(segmentInitSuccess()); + } else { + yield put(segmentInitUncertain()); } } @@ -202,20 +207,7 @@ export function* runUserSideEffectsSaga() { const isAirgappedInstance = isAirgapped(); if (enableTelemetry) { - // parallelize sentry and smart look initialization - - yield fork(intializeSmartLook, currentUser); - const initializeSentry = initializeAnalyticsAndTrackers(); - - if (initializeSentry instanceof Promise) { - const sentryInialized: boolean = yield initializeSentry; - - if (sentryInialized) { - yield put(segmentInitSuccess()); - } else { - yield put(segmentInitUncertain()); - } - } + yield fork(initTrackers, currentUser); } const isFFFetched: boolean = yield select(getFeatureFlagsFetched); diff --git a/app/client/src/utils/AppsmithUtils.tsx b/app/client/src/utils/AppsmithUtils.tsx index 0fad6ec8df..c86e6bd2f0 100644 --- a/app/client/src/utils/AppsmithUtils.tsx +++ b/app/client/src/utils/AppsmithUtils.tsx @@ -13,8 +13,10 @@ import type { JSCollectionData } from "ee/reducers/entityReducers/jsActionsReduc import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import type { CreateNewActionKeyInterface } from "ee/entities/Engine/actionHelpers"; import { CreateNewActionKey } from "ee/entities/Engine/actionHelpers"; +import { ANONYMOUS_USERNAME } from "../constants/userConstants"; +import type { User } from "constants/userConstants"; -export const initializeAnalyticsAndTrackers = async () => { +export const initializeAnalyticsAndTrackers = async (currentUser: User) => { const appsmithConfigs = getAppsmithConfigs(); try { @@ -106,6 +108,10 @@ export const initializeAnalyticsAndTrackers = async () => { Sentry.captureException(e); log.error(e); } + + if (!currentUser.isAnonymous && currentUser.username !== ANONYMOUS_USERNAME) { + await AnalyticsUtil.identifyUser(currentUser); + } }; export const mapToPropList = (map: Record): Property[] => {