diff --git a/app/client/src/UITelemetry/generateTraces.ts b/app/client/src/UITelemetry/generateTraces.ts index 0519ba7ceda6..ec1941e09e4f 100644 --- a/app/client/src/UITelemetry/generateTraces.ts +++ b/app/client/src/UITelemetry/generateTraces.ts @@ -14,10 +14,9 @@ import { osName, osVersion, } from "react-device-detect"; -import { APP_MODE } from "entities/App"; -import { matchBuilderPath, matchViewerPath } from "constants/routes"; import nanoid from "nanoid"; import memoizeOne from "memoize-one"; +import { getApplicationParamsFromUrl } from "ee/utils/serviceWorkerUtils"; const GENERATOR_TRACE = "generator-tracer"; @@ -26,25 +25,36 @@ export type SpanAttributes = Attributes; const OTLP_SESSION_ID = nanoid(); -const getAppMode = memoizeOne((pathname: string) => { - const isEditorUrl = matchBuilderPath(pathname); - const isViewerUrl = matchViewerPath(pathname); - - const appMode = isEditorUrl - ? APP_MODE.EDIT - : isViewerUrl - ? APP_MODE.PUBLISHED - : ""; - - return appMode; -}); +const getAppParams = memoizeOne( + (origin: string, pathname: string, search: string) => { + const applicationParams = getApplicationParamsFromUrl({ + origin, + pathname, + search, + }); + + const { + applicationSlug, + appMode = "", + basePageId: pageId, + branchName, + } = applicationParams || {}; + + return { + appMode, + pageId, + branchName, + applicationSlug, + }; + }, +); export const getCommonTelemetryAttributes = () => { - const pathname = window.location.pathname; - const appMode = getAppMode(pathname); + const { origin, pathname, search } = window.location; + const appParams = getAppParams(origin, pathname, search); return { - appMode, + ...appParams, deviceType, browserName, browserVersion, diff --git a/app/client/src/ce/utils/serviceWorkerUtils.test.ts b/app/client/src/ce/utils/serviceWorkerUtils.test.ts index 87c07a50c60f..5a71363c89e1 100644 --- a/app/client/src/ce/utils/serviceWorkerUtils.test.ts +++ b/app/client/src/ce/utils/serviceWorkerUtils.test.ts @@ -212,6 +212,7 @@ describe("serviceWorkerUtils", () => { const expectedParams: TApplicationParams = { origin: "https://app.appsmith.com", basePageId, + applicationSlug: "my-app", baseApplicationId: undefined, branchName: "main", appMode: APP_MODE.EDIT, @@ -227,6 +228,7 @@ describe("serviceWorkerUtils", () => { const expectedParams: TApplicationParams = { origin: "https://app.appsmith.com", basePageId, + applicationSlug: "my-app", baseApplicationId: undefined, branchName: "main", appMode: APP_MODE.PUBLISHED, @@ -307,6 +309,7 @@ describe("serviceWorkerUtils", () => { ); const expectedParams: TApplicationParams = { origin: "https://app.appsmith.com", + applicationSlug: "my-app", basePageId, baseApplicationId: undefined, branchName: "", diff --git a/app/client/src/ce/utils/serviceWorkerUtils.ts b/app/client/src/ce/utils/serviceWorkerUtils.ts index 1d359270188b..7d729e72826d 100644 --- a/app/client/src/ce/utils/serviceWorkerUtils.ts +++ b/app/client/src/ce/utils/serviceWorkerUtils.ts @@ -14,6 +14,7 @@ import { interface TMatchResult { basePageId?: string; baseApplicationId?: string; + applicationSlug?: string; } export interface TApplicationParams { @@ -22,6 +23,7 @@ export interface TApplicationParams { baseApplicationId?: string; branchName: string; appMode: APP_MODE; + applicationSlug?: string; } type TApplicationParamsOrNull = TApplicationParams | null; @@ -57,33 +59,36 @@ export const getSearchQuery = (search = "", key: string) => { }; export const getApplicationParamsFromUrl = ( - url: URL, + urlParams: Pick, ): TApplicationParamsOrNull => { + const { origin, pathname, search } = urlParams; // Get the branch name from the query string - const branchName = getSearchQuery(url.search, "branch"); + const branchName = getSearchQuery(search, "branch"); - const matchedBuilder: Match = matchBuilderPath(url.pathname, { + const matchedBuilder: Match = matchBuilderPath(pathname, { end: false, }); - const matchedViewer: Match = matchViewerPath(url.pathname); + const matchedViewer: Match = matchViewerPath(pathname); if (matchedBuilder) { return { - origin: url.origin, + origin, basePageId: matchedBuilder.params.basePageId, baseApplicationId: matchedBuilder.params.baseApplicationId, branchName, appMode: APP_MODE.EDIT, + applicationSlug: matchedBuilder.params.applicationSlug, }; } if (matchedViewer) { return { - origin: url.origin, + origin, basePageId: matchedViewer.params.basePageId, baseApplicationId: matchedViewer.params.baseApplicationId, branchName, appMode: APP_MODE.PUBLISHED, + applicationSlug: matchedViewer.params.applicationSlug, }; }