diff --git a/package-lock.json b/package-lock.json index 64728cb6..637ac128 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "rimraf": "^3.0.2", "save-svg-as-png": "^1.4.17", "shell-path": "^3.0.0", - "systeminformation": "^5.21.7", + "systeminformation": "5.21.7", "win32-api": "^20.1.0" }, "devDependencies": { diff --git a/spec/snippingTool.spec.tsx b/spec/snippingTool.spec.tsx index 0207c3ac..aa241f69 100644 --- a/spec/snippingTool.spec.tsx +++ b/spec/snippingTool.spec.tsx @@ -8,7 +8,7 @@ jest.mock('save-svg-as-png', function () { import { mount, shallow } from 'enzyme'; import * as React from 'react'; -import { ScreenSnippetActionTypes } from '../src/app/analytics-handler'; +import { ScreenSnippetActionTypes } from '../src/app/bi/analytics-handler'; import { ScreenShotAnnotation } from '../src/common/ipcEvent'; import SnippingTool from '../src/renderer/components/snipping-tool'; import { ipcRenderer } from './__mocks__/electron'; diff --git a/src/app/app-menu.ts b/src/app/app-menu.ts index ac89215e..cb66da21 100644 --- a/src/app/app-menu.ts +++ b/src/app/app-menu.ts @@ -15,7 +15,7 @@ import { AnalyticsActions, AnalyticsElements, MenuActionTypes, -} from './analytics-handler'; +} from './bi/analytics-handler'; import { CloudConfigDataTypes, config, IConfig } from './config-handler'; import { restartDialog, titleBarChangeDialog } from './dialog-handler'; import { exportCrashDumps, exportLogs } from './reports-handler'; diff --git a/src/app/auto-update-handler.ts b/src/app/auto-update-handler.ts index 795b0650..124a9f7d 100644 --- a/src/app/auto-update-handler.ts +++ b/src/app/auto-update-handler.ts @@ -2,19 +2,12 @@ import { GenericServerOptions } from 'builder-util-runtime'; import electronLog from 'electron-log'; import { MacUpdater, NsisUpdater } from 'electron-updater'; -import { app } from 'electron'; import { isMac, isWindowsOS } from '../common/env'; import { logger } from '../common/logger'; import { isUrl } from '../common/utils'; import { whitelistHandler } from '../common/whitelist-handler'; -import { - analytics, - AnalyticsElements, - IInstallData, - InstallActionTypes, - InstallLocationTypes, - InstallTypes, -} from './analytics-handler'; +import { InstallActionTypes, InstallTypes } from './bi/analytics-handler'; +import { sendAutoUpdateAnalytics } from './bi/auto-update-analytics'; import { config } from './config-handler'; import { retrieveWindowsRegistry } from './registry-handler'; import { EChannelRegistry, RegistryStore } from './stores/registry-store'; @@ -106,7 +99,10 @@ export class AutoUpdate { if (!this.isUpdateAvailable) { return; } - this.sendAnalytics(InstallActionTypes.InstallStarted, InstallTypes.Auto); + sendAutoUpdateAnalytics( + InstallActionTypes.InstallStarted, + InstallTypes.Auto, + ); // Handle update and restart for macOS if (isMac) { windowHandler.setIsAutoUpdating(true); @@ -179,24 +175,7 @@ export class AutoUpdate { return updateUrl; }; - /** - * Sends install analytics - */ - public sendAnalytics = ( - action: InstallActionTypes, - installType: InstallTypes, - ) => { - const installLocation = this.getInstallLocation(); - const event: IInstallData = { - element: AnalyticsElements.SDA_INSTALL, - action_type: action, - extra_data: { - installLocation, - installType, - }, - }; - analytics.track(event); - }; + private updateEventHandler = async (info, eventType: string) => { const mainWebContents = windowHandler.mainWebContents; if (mainWebContents && !mainWebContents.isDestroyed()) { @@ -282,30 +261,6 @@ export class AutoUpdate { } } }; - - /** - * Identifies and returns the installation location - */ - private getInstallLocation = () => { - const appPath = app.getPath('exe'); - if (isWindowsOS) { - if (appPath.includes('AppData\\Local\\Programs')) { - return InstallLocationTypes.LOCAL; - } - if (appPath.includes('Program Files')) { - return InstallLocationTypes.PROG_FILES; - } - return InstallLocationTypes.CUSTOM; - } - if (isMac) { - if (appPath.includes('/Applications')) { - return InstallLocationTypes.PROG_FILES; - } - return InstallLocationTypes.LOCAL; - } - - return InstallLocationTypes.PROG_FILES; - }; } const autoUpdate = new AutoUpdate(); diff --git a/src/app/analytics-handler.ts b/src/app/bi/analytics-handler.ts similarity index 100% rename from src/app/analytics-handler.ts rename to src/app/bi/analytics-handler.ts diff --git a/src/app/bi/auto-update-analytics.ts b/src/app/bi/auto-update-analytics.ts new file mode 100644 index 00000000..6442a281 --- /dev/null +++ b/src/app/bi/auto-update-analytics.ts @@ -0,0 +1,55 @@ +import { app } from 'electron'; +import { isMac, isWindowsOS } from '../../common/env'; +import { + analytics, + AnalyticsElements, + IInstallData, + InstallActionTypes, + InstallLocationTypes, + InstallTypes, +} from './analytics-handler'; + +/** + * Sends auto update analytics event + * @param action + * @param installType + */ +export const sendAutoUpdateAnalytics = ( + action: InstallActionTypes, + installType: InstallTypes, +) => { + const installLocation = getInstallLocation(); + const event: IInstallData = { + element: AnalyticsElements.SDA_INSTALL, + action_type: action, + extra_data: { + installLocation, + installType, + }, + }; + analytics.track(event); +}; + +/** + * Identifies and returns the installation location + */ +const getInstallLocation = () => { + const appPath = app.getPath('exe'); + if (isWindowsOS) { + if (appPath.includes('AppData\\Local\\Programs')) { + return InstallLocationTypes.LOCAL; + } + if (appPath.includes('Program Files')) { + return InstallLocationTypes.PROG_FILES; + } + return InstallLocationTypes.CUSTOM; + } + if (isMac) { + if (appPath.includes('/Applications')) { + return InstallLocationTypes.PROG_FILES; + } + return InstallLocationTypes.LOCAL; + } + + return InstallLocationTypes.PROG_FILES; +}; diff --git a/src/app/config-handler.ts b/src/app/config-handler.ts index 5248b48b..041fc9bc 100644 --- a/src/app/config-handler.ts +++ b/src/app/config-handler.ts @@ -12,8 +12,8 @@ import { InstallTypes, SDAEndReasonTypes, SDAUserSessionActionTypes, -} from './analytics-handler'; -import { autoUpdate } from './auto-update-handler'; +} from './bi/analytics-handler'; +import { sendAutoUpdateAnalytics } from './bi/auto-update-analytics'; import { appStats } from './stats'; const writeFile = util.promisify(fs.writeFile); @@ -638,7 +638,7 @@ class Config { ); this.isFirstTime = true; this.bootCount = 0; - autoUpdate.sendAnalytics( + sendAutoUpdateAnalytics( InstallActionTypes.InstallCompleted, InstallTypes.Manual, ); @@ -653,7 +653,7 @@ class Config { await this.setUpFirstTimeLaunch(); // Skip welcome screen this.isFirstTime = false; - autoUpdate.sendAnalytics( + sendAutoUpdateAnalytics( InstallActionTypes.InstallCompleted, InstallTypes.Auto, ); @@ -670,7 +670,7 @@ class Config { ); this.isFirstTime = true; this.bootCount = 0; - autoUpdate.sendAnalytics( + sendAutoUpdateAnalytics( InstallActionTypes.InstallCompleted, InstallTypes.Manual, ); diff --git a/src/app/crash-handler.ts b/src/app/crash-handler.ts index a33141c4..8e8d7592 100644 --- a/src/app/crash-handler.ts +++ b/src/app/crash-handler.ts @@ -13,7 +13,7 @@ import { AnalyticsElements, ICrashData, SDACrashProcess, -} from './analytics-handler'; +} from './bi/analytics-handler'; import { ICustomBrowserWindow } from './window-handler'; import { windowExists } from './window-utils'; diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index 52eaec62..51c9b0b0 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -20,8 +20,8 @@ import { i18n, LocaleType } from '../common/i18n'; import { logger } from '../common/logger'; import { whitelistHandler } from '../common/whitelist-handler'; import { activityDetection } from './activity-detection'; -import { analytics, SDAUserSessionActionTypes } from './analytics-handler'; import appStateHandler from './app-state-handler'; +import { analytics, SDAUserSessionActionTypes } from './bi/analytics-handler'; import { closeC9Pipe, connectC9Pipe, writeC9Pipe } from './c9-pipe-handler'; import { loadC9Shell, terminateC9Shell } from './c9-shell-handler'; import { getCitrixMediaRedirectionStatus } from './citrix-handler'; diff --git a/src/app/memory-monitor.ts b/src/app/memory-monitor.ts index 383a753e..30a25476 100644 --- a/src/app/memory-monitor.ts +++ b/src/app/memory-monitor.ts @@ -2,7 +2,7 @@ import * as electron from 'electron'; import { isMac } from '../common/env'; import { logger } from '../common/logger'; -import { SDAUserSessionActionTypes } from './analytics-handler'; +import { SDAUserSessionActionTypes } from './bi/analytics-handler'; import { CloudConfigDataTypes, config } from './config-handler'; import { appStats } from './stats'; import { windowHandler } from './window-handler'; diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 0af21ddc..5289b9db 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -29,7 +29,7 @@ import { analytics, AnalyticsElements, ScreenSnippetActionTypes, -} from './analytics-handler'; +} from './bi/analytics-handler'; import { winStore } from './stores'; import { IWindowState } from './stores/window-store'; import { updateAlwaysOnTop } from './window-actions'; diff --git a/src/app/stats.ts b/src/app/stats.ts index f4df1895..9985a3f5 100644 --- a/src/app/stats.ts +++ b/src/app/stats.ts @@ -13,7 +13,7 @@ import { ISessionData, SDAEndReasonTypes, SDAUserSessionActionTypes, -} from './analytics-handler'; +} from './bi/analytics-handler'; const MAX_USAGE_CHECK_INTERVAL = 15 * 60 * 1000; // every 15min @@ -150,6 +150,12 @@ export class AppStats { logger.error(`stats: parsing stats JSON file failed due to error ${e}`); } } + if (this.stats.length > 0) { + this.stats.forEach((event) => { + analytics.track(event); + }); + this.stats = []; + } }; /** diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index b7a2411a..07af62e4 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -38,12 +38,12 @@ import { throttle, } from '../common/utils'; import { notification } from '../renderer/notification'; +import { cleanAppCacheOnCrash } from './app-cache-handler'; +import { AppMenu } from './app-menu'; import { SDAEndReasonTypes, SDAUserSessionActionTypes, -} from './analytics-handler'; -import { cleanAppCacheOnCrash } from './app-cache-handler'; -import { AppMenu } from './app-menu'; +} from './bi/analytics-handler'; import { closeC9Pipe } from './c9-pipe-handler'; import { handleChildWindow } from './child-window-handler'; import { diff --git a/src/renderer/app-bridge.ts b/src/renderer/app-bridge.ts index 851b21c8..224ff302 100644 --- a/src/renderer/app-bridge.ts +++ b/src/renderer/app-bridge.ts @@ -1,5 +1,5 @@ import { ipcRenderer } from 'electron'; -import { IAnalyticsData } from '../app/analytics-handler'; +import { IAnalyticsData } from '../app/bi/analytics-handler'; import { apiCmds, apiName, diff --git a/src/renderer/components/annotate-area.tsx b/src/renderer/components/annotate-area.tsx index 7d48fb98..dba2e431 100644 --- a/src/renderer/components/annotate-area.tsx +++ b/src/renderer/components/annotate-area.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; import { AnalyticsElements, ScreenSnippetActionTypes, -} from './../../app/analytics-handler'; +} from '../../app/bi/analytics-handler'; import { IDimensions, IPath, diff --git a/src/renderer/components/snipping-tool.tsx b/src/renderer/components/snipping-tool.tsx index 5c159bf7..874afcae 100644 --- a/src/renderer/components/snipping-tool.tsx +++ b/src/renderer/components/snipping-tool.tsx @@ -1,15 +1,15 @@ import { ipcRenderer } from 'electron'; import * as React from 'react'; import { svgAsPngUri } from 'save-svg-as-png'; +import { + AnalyticsElements, + ScreenSnippetActionTypes, +} from '../../app/bi/analytics-handler'; import { i18n } from '../../common/i18n-preload'; import { ScreenShotAnnotation } from '../../common/ipcEvent'; import * as PenIcon from '../../renderer/assets/snip-draw.svg'; import * as EraseIcon from '../../renderer/assets/snip-erase.svg'; import * as HighlightIcon from '../../renderer/assets/snip-highlight.svg'; -import { - AnalyticsElements, - ScreenSnippetActionTypes, -} from './../../app/analytics-handler'; import AnnotateArea from './annotate-area'; import ColorPickerPill, { IColor } from './color-picker-pill'; import MenuButton from './menu-button'; diff --git a/src/renderer/notification.ts b/src/renderer/notification.ts index 32e12360..28973d42 100644 --- a/src/renderer/notification.ts +++ b/src/renderer/notification.ts @@ -4,7 +4,7 @@ import { analytics, AnalyticsElements, ToastNotificationActionTypes, -} from '../app/analytics-handler'; +} from '../app/bi/analytics-handler'; import { config } from '../app/config-handler'; import { AUX_CLICK,