From 5e89edf8c416748e3c303d7328e79fd3b1e58c11 Mon Sep 17 00:00:00 2001 From: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:20:14 +0530 Subject: [PATCH] feat: Added analytics for pulse failure (#37781) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes https://github.com/appsmithorg/appsmith-ee/issues/5606 ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 18929d475592e0f9fca0be0d13f09ddab031f6b8 > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Wed, 27 Nov 2024 11:51:54 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit - **New Features** - Enhanced analytics tracking with new event types: "CANVAS_HOVER" and "MALFORMED_USAGE_PULSE". - Improved error reporting in the `fetchWithRetry` function, capturing additional context during failures. - **Bug Fixes** - Added logging for better monitoring of malformed usage scenarios. --- app/client/src/ce/utils/analyticsUtilTypes.ts | 3 ++- app/client/src/usagePulse/utils.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/client/src/ce/utils/analyticsUtilTypes.ts b/app/client/src/ce/utils/analyticsUtilTypes.ts index 9bb8ea464f..ede9702143 100644 --- a/app/client/src/ce/utils/analyticsUtilTypes.ts +++ b/app/client/src/ce/utils/analyticsUtilTypes.ts @@ -351,7 +351,8 @@ export type EventName = | "EDITOR_MODE_CHANGE" | BUILDING_BLOCKS_EVENTS | "VISIT_SELF_HOST_DOCS" - | "CANVAS_HOVER"; + | "CANVAS_HOVER" + | "MALFORMED_USAGE_PULSE"; type HOMEPAGE_CREATE_APP_FROM_TEMPLATE_EVENTS = | "TEMPLATE_DROPDOWN_CLICK" diff --git a/app/client/src/usagePulse/utils.ts b/app/client/src/usagePulse/utils.ts index 9d058e314b..29ed44891a 100644 --- a/app/client/src/usagePulse/utils.ts +++ b/app/client/src/usagePulse/utils.ts @@ -6,6 +6,7 @@ import { getAppMode } from "ee/selectors/entitiesSelector"; import store from "store"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { FALLBACK_KEY } from "ee/constants/UsagePulse"; +import { getInstanceId } from "ee/selectors/tenantSelectors"; //TODO (Dipyaman): We should return a promise that will get resolved only on success or rejected after the retries export const fetchWithRetry = (config: { @@ -16,6 +17,9 @@ export const fetchWithRetry = (config: { retries: number; retryTimeout: number; }) => { + const instanceId = getInstanceId(store.getState()); + const anonymousUserId = AnalyticsUtil.getAnonymousId(); + fetch(config.url, { method: "POST", credentials: "same-origin", @@ -36,6 +40,12 @@ export const fetchWithRetry = (config: { retries: config.retries - 1, retryTimeout: config.retryTimeout, }); + } else { + // add analytics for failed usage pulse + AnalyticsUtil.logEvent("MALFORMED_USAGE_PULSE", { + anonymousUserId, + instanceId, + }); } }); };