fix: Analytics identify user not called correctly (#37303)

## 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"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11742239861>
> Commit: 984e325a14e8c4f9d3a0ac87d31365728b37785e
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11742239861&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Fri, 08 Nov 2024 13:16:33 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Hetu Nandu 2024-11-11 10:47:32 +05:30 committed by GitHub
parent c2bf6c830e
commit ec1d737edc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 19 deletions

View File

@ -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);

View File

@ -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<string, string>): Property[] => {