UNPKG

@finos/legend-application-marketplace

Version:
367 lines 15.2 kB
/** * Copyright (c) 2025-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { V1_ResourceType, } from '@finos/legend-graph'; import { LEGEND_MARKETPLACE_APP_EVENT } from './LegendMarketplaceAppEvent.js'; import { uuid } from '@finos/legend-shared'; import { SEARCH_SESSION_KEY, TELEMETRY_EVENT_STATUS, } from '@finos/legend-extension-dsl-data-product'; export var LEGEND_MARKETPLACE_PAGE; (function (LEGEND_MARKETPLACE_PAGE) { LEGEND_MARKETPLACE_PAGE["HOME_PAGE"] = "Home Page"; LEGEND_MARKETPLACE_PAGE["SEARCH_RESULTS_PAGE"] = "Search Results Page"; })(LEGEND_MARKETPLACE_PAGE || (LEGEND_MARKETPLACE_PAGE = {})); export var CONTRACT_ACTION; (function (CONTRACT_ACTION) { CONTRACT_ACTION["APPROVED"] = "approved"; CONTRACT_ACTION["DENIED"] = "denied"; })(CONTRACT_ACTION || (CONTRACT_ACTION = {})); export var ICON_TOOLBAR_TYPE; (function (ICON_TOOLBAR_TYPE) { ICON_TOOLBAR_TYPE["USER"] = "User Icon"; ICON_TOOLBAR_TYPE["HELP"] = "Help Icon"; })(ICON_TOOLBAR_TYPE || (ICON_TOOLBAR_TYPE = {})); export class LegendMarketplaceTelemetryHelper { static getOrCreateUserSession() { const stored = localStorage.getItem(SEARCH_SESSION_KEY); if (stored) { const session = JSON.parse(stored); return session; } else { const initialSession = { eventId: 0, searchSessionId: undefined, }; localStorage.setItem(SEARCH_SESSION_KEY, JSON.stringify(initialSession)); return initialSession; } } static updateSearchSessionId(searchSessionId) { const currentSession = this.getOrCreateUserSession(); const newSearchSession = { ...currentSession, searchSessionId: searchSessionId, }; localStorage.setItem(SEARCH_SESSION_KEY, JSON.stringify(newSearchSession)); return newSearchSession; } static clearSearchSessionId() { const currentSession = this.getOrCreateUserSession(); const newSearchSession = { ...currentSession, searchSessionId: undefined, }; if (currentSession.eventId !== 0) { localStorage.setItem(SEARCH_SESSION_KEY, JSON.stringify(newSearchSession)); } return newSearchSession; } static updateEventId() { const currentSession = this.getOrCreateUserSession(); const updatedSession = { ...currentSession, eventId: currentSession.eventId + 1, }; localStorage.setItem(SEARCH_SESSION_KEY, JSON.stringify(updatedSession)); return updatedSession; } static logEvent_ClickingDataProductCard(telemetryService, dataProductData, clickedFrom) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_DATA_PRODUCT_CARD, { ...dataProductData, clickedFrom: clickedFrom, ...session, }); } static logEvent_SearchQuery(telemetryService, query, useProducerSearch, searchedFrom, useFieldSearch = false) { this.updateSearchSessionId(uuid()); this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.SEARCH_QUERY, { query, useProducerSearch, useFieldSearch, searchedFrom, ...session, }); } static logEvent_ActionDataContracts(telemetryService, selectedContracts, pendingTaskContracts, action, actionTakenBy, errors) { this.updateEventId(); const session = this.getOrCreateUserSession(); const actionedContractsDetails = selectedContracts.map((contract) => { const dataContract = pendingTaskContracts?.find((c) => c.guid === contract.dataContractId); const accessPointGroup = dataContract?.resourceType === V1_ResourceType.ACCESS_POINT_GROUP ? dataContract.accessPointGroup : `${dataContract?.accessPointGroup ?? 'Unknown'} (${dataContract?.resourceType ?? 'Unknown Type'})`; return { taskId: contract.taskId, dataContractId: contract.dataContractId, consumer: contract.consumer, type: contract.type, targetDataProduct: dataContract?.resourceId ?? 'Unknown', targetAccessPointGroup: accessPointGroup ?? 'Unknown', requester: dataContract?.createdBy, ...session, }; }); const data = errors === undefined ? { actionedContractsDetails: actionedContractsDetails, action: action, actionTakenBy: actionTakenBy, status: TELEMETRY_EVENT_STATUS.SUCCESS, } : { actionedContractsDetails: actionedContractsDetails, action: action, actionTakenBy: actionTakenBy, status: TELEMETRY_EVENT_STATUS.FAILURE, errors: errors, }; telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.ACTION_DATA_CONTRACTS, data); } static logEvent_LoadDataProduct(telemetryService, dataProductData, error) { const telemetryData = error === undefined ? { ...dataProductData, status: TELEMETRY_EVENT_STATUS.SUCCESS } : { ...dataProductData, status: TELEMETRY_EVENT_STATUS.FAILURE, error: error, }; telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.LOAD_DATA_PRODUCT, telemetryData); } static logEvent_LoadSDLCDataProduct(telemetryService, dataProductData, error) { const telemetryData = error === undefined ? { ...dataProductData, status: TELEMETRY_EVENT_STATUS.SUCCESS } : { ...dataProductData, status: TELEMETRY_EVENT_STATUS.FAILURE, error: error, }; telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.LOAD_SDLC_DATA_PRODUCT, telemetryData); } static logEvent_LoadTerminal(telemetryService, terminalId, error) { const telemetryData = error === undefined ? { terminalId: terminalId, status: TELEMETRY_EVENT_STATUS.SUCCESS } : { terminalId: terminalId, status: TELEMETRY_EVENT_STATUS.FAILURE, error: error, }; telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.LOAD_TERMINAL, telemetryData); } static logEvent_LoadLegacyDataProduct(telemetryService, groupId, artifactId, versionId, path, error) { const telemetryData = error === undefined ? { groupId: groupId, artifactId: artifactId, versionId: versionId, path: path, status: TELEMETRY_EVENT_STATUS.SUCCESS, } : { groupId: groupId, artifactId: artifactId, versionId: versionId, path: path, status: TELEMETRY_EVENT_STATUS.FAILURE, error: error, }; telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.LOAD_LEGACY_DATA_PRODUCT, telemetryData); } static logEvent_ClickHeadertab(telemetryService, tabTitle) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_HEADER_TAB, { tabTitle: tabTitle, ...session, }); } static logEvent_ToggleProducerSearch(telemetryService, isEnabled) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.PRODUCER_SEARCH_TOGGLE, { toggleAction: isEnabled ? 'enabled' : 'disabled', ...session, }); } static logEvent_ToggleFieldSearch(telemetryService, isEnabled) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.FIELD_SEARCH_TOGGLE, { toggleAction: isEnabled ? 'enabled' : 'disabled', ...session, }); } static logEvent_ToggleThemeMode(telemetryService, isDarkMode) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.TOGGLE_THEME_MODE, { currentTheme: isDarkMode ? 'dark' : 'light', ...session, }); } static logEvent_ToggleViewMode(telemetryService, viewMode) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.TOGGLE_VIEW_MODE, { viewMode, ...session, }); } static logEvent_ToggleServicesViewMode(telemetryService, viewMode) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.TOGGLE_SERVICES_VIEW_MODE, { viewMode, ...session, }); } static logEvent_ClickToolbarMenu(telemetryService, iconSource, menuTitle) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_TOOLBAR_MENU, { iconSource: iconSource, menuTitle: menuTitle, ...session, }); } static logEvent_SearchAutosuggestSelection(telemetryService, query, suggestionType) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.SEARCH_AUTOSUGGEST_SELECTION, { query: query, suggestionType: suggestionType, ...session, }); } static logEvent_DismissHomePageBanner(telemetryService, bannerId) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.DISMISS_HOME_PAGE_BANNER, { bannerId: bannerId, ...session, }); } static logEvent_SubmitFeedback(telemetryService, originPage, rating) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.SUBMIT_FEEDBACK, { originPage: originPage, rating: rating, ...session, }); } static logEvent_ClickQueryDataProduct(telemetryService, groupId, artifactId, versionId, path, executionContextKey) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_QUERY_DATA_PRODUCT, { groupId: groupId, artifactId: artifactId, versionId: versionId, path: path, executionContextKey: executionContextKey, ...session, }); } static logEvent_ClickOpenServiceQuery(telemetryService, groupId, artifactId, versionId, servicePath) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_OPEN_SERVICE_QUERY, { groupId: groupId, artifactId: artifactId, versionId: versionId, servicePath: servicePath, ...session, }); } static logEvent_ClickQuickStartExtensionTab(telemetryService, groupId, artifactId, versionId, path, tabKey, executableTitle) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_QUICKSTART_EXTENSION_TAB, { groupId: groupId, artifactId: artifactId, versionId: versionId, path: path, tabKey: tabKey, executableTitle: executableTitle, ...session, }); } static logEvent_ApplySearchFilter(telemetryService, filterType, filterValue, action, searchQuery) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.APPLY_SEARCH_FILTER, { filterType, filterValue, action, searchQuery, ...session, }); } static logEvent_ClearSearchFilters(telemetryService, searchQuery) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLEAR_SEARCH_FILTERS, { searchQuery, ...session, }); } static logEvent_ShowAllDataProducts(telemetryService, searchQuery) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.SHOW_ALL_DATA_PRODUCTS, { searchQuery, ...session, }); } static logEvent_SearchServices(telemetryService, query) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.SEARCH_SERVICES, { query, ...session, }); } static logEvent_SortServices(telemetryService, sortValue) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.SORT_SERVICES, { sortValue, ...session, }); } static logEvent_FilterServices(telemetryService, filterType, filterValue, action) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.FILTER_SERVICES, { filterType, filterValue, action, ...session, }); } static logEvent_ClickServiceCard(telemetryService, pattern, title) { this.updateEventId(); const session = this.getOrCreateUserSession(); telemetryService.logEvent(LEGEND_MARKETPLACE_APP_EVENT.CLICK_SERVICE_CARD, { pattern, title, ...session, }); } } //# sourceMappingURL=LegendMarketplaceTelemetryHelper.js.map