From a8380a0f7645b67b77724e204b338aba80b471d5 Mon Sep 17 00:00:00 2001 From: Favour Ohanekwu Date: Wed, 22 Nov 2023 09:48:12 +0100 Subject: [PATCH] chore: Prevent logging error analytics on first page load (#29019) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This PR prevents logging of error analytics on first page load, and page navigation #### PR fixes following issue(s) Fixes #29018 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- app/client/src/sagas/DebuggerSagas.ts | 72 ++++++++++++++----------- app/client/src/sagas/EvaluationsSaga.ts | 3 +- app/client/src/utils/AnalyticsUtil.tsx | 21 +++++++- 3 files changed, 63 insertions(+), 33 deletions(-) diff --git a/app/client/src/sagas/DebuggerSagas.ts b/app/client/src/sagas/DebuggerSagas.ts index e837cb9eef..af8f9e2423 100644 --- a/app/client/src/sagas/DebuggerSagas.ts +++ b/app/client/src/sagas/DebuggerSagas.ts @@ -51,7 +51,7 @@ import { } from "@appsmith/constants/messages"; import AppsmithConsole from "utils/AppsmithConsole"; import { getWidget } from "./selectors"; -import AnalyticsUtil from "utils/AnalyticsUtil"; +import AnalyticsUtil, { AnalyticsEventType } from "utils/AnalyticsUtil"; import type { Plugin } from "api/PluginApi"; import { getCurrentPageId } from "selectors/editorSelectors"; import type { WidgetProps } from "widgets/BaseWidget"; @@ -421,16 +421,20 @@ function* logDebuggerErrorAnalyticsSaga( const propertyPath = `${widgetType}.${payload.propertyPath}`; // Sending widget type for widgets - AnalyticsUtil.logEvent(payload.eventName, { - entityType: widgetType, - propertyPath, - errorId: payload.errorId, - errorMessages: payload.errorMessages, - pageId: currentPageId, - errorMessage: payload.errorMessage, - errorType: payload.errorType, - appMode: payload.appMode, - }); + AnalyticsUtil.logEvent( + payload.eventName, + { + entityType: widgetType, + propertyPath, + errorId: payload.errorId, + errorMessages: payload.errorMessages, + pageId: currentPageId, + errorMessage: payload.errorMessage, + errorType: payload.errorType, + appMode: payload.appMode, + }, + AnalyticsEventType.error, + ); } else if (payload.entityType === ENTITY_TYPE.ACTION) { const action: Action | undefined = yield select( getAction, @@ -446,17 +450,21 @@ function* logDebuggerErrorAnalyticsSaga( } // Sending plugin name for actions - AnalyticsUtil.logEvent(payload.eventName, { - entityType: pluginName, - propertyPath, - errorId: payload.errorId, - errorMessages: payload.errorMessages, - pageId: currentPageId, - errorMessage: payload.errorMessage, - errorType: payload.errorType, - errorSubType: payload.errorSubType, - appMode: payload.appMode, - }); + AnalyticsUtil.logEvent( + payload.eventName, + { + entityType: pluginName, + propertyPath, + errorId: payload.errorId, + errorMessages: payload.errorMessages, + pageId: currentPageId, + errorMessage: payload.errorMessage, + errorType: payload.errorType, + errorSubType: payload.errorSubType, + appMode: payload.appMode, + }, + AnalyticsEventType.error, + ); } else if (payload.entityType === ENTITY_TYPE.JSACTION) { const action: JSCollection = yield select( getJSCollection, @@ -467,14 +475,18 @@ function* logDebuggerErrorAnalyticsSaga( const pluginName = plugin?.name?.replace(/ /g, ""); // Sending plugin name for actions - AnalyticsUtil.logEvent(payload.eventName, { - entityType: pluginName, - errorId: payload.errorId, - propertyPath: payload.propertyPath, - errorMessages: payload.errorMessages, - pageId: currentPageId, - appMode: payload.appMode, - }); + AnalyticsUtil.logEvent( + payload.eventName, + { + entityType: pluginName, + errorId: payload.errorId, + propertyPath: payload.propertyPath, + errorMessages: payload.errorMessages, + pageId: currentPageId, + appMode: payload.appMode, + }, + AnalyticsEventType.error, + ); } } catch (e) { log.error(e); diff --git a/app/client/src/sagas/EvaluationsSaga.ts b/app/client/src/sagas/EvaluationsSaga.ts index 7754f993a1..0191b1bda8 100644 --- a/app/client/src/sagas/EvaluationsSaga.ts +++ b/app/client/src/sagas/EvaluationsSaga.ts @@ -102,6 +102,7 @@ import { fetchFeatureFlagsInit } from "actions/userActions"; import { parseUpdatesAndDeleteUndefinedUpdates } from "./EvaluationSaga.utils"; import { getFeatureFlagsFetched } from "selectors/usersSelectors"; import { evalErrorHandler } from "./EvalErrorHandler"; +import AnalyticsUtil from "utils/AnalyticsUtil"; const APPSMITH_CONFIGS = getAppsmithConfigs(); export const evalWorker = new GracefulWorkerService( @@ -189,7 +190,7 @@ export function* updateDataTreeHandler( configTree, removedPaths, ); - + AnalyticsUtil.setBlockErrorLogs(isCreateFirstTree); if (appMode !== APP_MODE.PUBLISHED) { const jsData: Record = yield select(getAllJSActionsData); postEvalActionsToDispatch.push(executeJSUpdates(jsUpdates)); diff --git a/app/client/src/utils/AnalyticsUtil.tsx b/app/client/src/utils/AnalyticsUtil.tsx index 5faa1fa5a9..19d972455a 100644 --- a/app/client/src/utils/AnalyticsUtil.tsx +++ b/app/client/src/utils/AnalyticsUtil.tsx @@ -28,13 +28,17 @@ function getApplicationId(location: Location) { return appId; } +export enum AnalyticsEventType { + error = "error", +} + class AnalyticsUtil { static cachedAnonymoustId: string; static cachedUserId: string; static user?: User = undefined; static blockTrackEvent: boolean | undefined; static instanceId?: string = ""; - + static blockErrorLogs = false; static initializeSmartLook(id: string) { smartlookClient.init(id); } @@ -119,10 +123,20 @@ class AnalyticsUtil { return initPromise; } - static logEvent(eventName: EventName, eventData: any = {}) { + static logEvent( + eventName: EventName, + eventData: any = {}, + eventType?: AnalyticsEventType, + ) { if (AnalyticsUtil.blockTrackEvent) { return; } + if ( + AnalyticsUtil.blockErrorLogs && + eventType === AnalyticsEventType.error + ) { + return; + } const windowDoc: any = window; let finalEventData = eventData; @@ -255,6 +269,9 @@ class AnalyticsUtil { AnalyticsUtil.blockTrackEvent = false; (window as any).analytics = undefined; } + static setBlockErrorLogs(value: boolean) { + AnalyticsUtil.blockErrorLogs = value; + } } export default AnalyticsUtil;