Skip to content

Commit

Permalink
SDA-4359 - Refactor BI & send in memory session analytic events
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan authored and Kiran Niranjan committed Oct 5, 2023
1 parent 244468a commit 08ffae9
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/snippingTool.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/app-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
56 changes: 4 additions & 52 deletions src/app/auto-update-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { sendAnalytics } from './bi/auto-update-analytics';
import { config } from './config-handler';
import { retrieveWindowsRegistry } from './registry-handler';
import { EChannelRegistry, RegistryStore } from './stores/registry-store';
Expand Down Expand Up @@ -106,7 +99,7 @@ export class AutoUpdate {
if (!this.isUpdateAvailable) {
return;
}
this.sendAnalytics(InstallActionTypes.InstallStarted, InstallTypes.Auto);
sendAnalytics(InstallActionTypes.InstallStarted, InstallTypes.Auto);
// Handle update and restart for macOS
if (isMac) {
windowHandler.setIsAutoUpdating(true);
Expand Down Expand Up @@ -179,24 +172,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()) {
Expand Down Expand Up @@ -282,30 +258,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();
Expand Down
File renamed without changes.
55 changes: 55 additions & 0 deletions src/app/bi/auto-update-analytics.ts
Original file line number Diff line number Diff line change
@@ -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 sendAnalytics = (
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;
};
19 changes: 5 additions & 14 deletions src/app/config-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
InstallTypes,
SDAEndReasonTypes,
SDAUserSessionActionTypes,
} from './analytics-handler';
import { autoUpdate } from './auto-update-handler';
} from './bi/analytics-handler';
import { sendAnalytics } from './bi/auto-update-analytics';
import { appStats } from './stats';

const writeFile = util.promisify(fs.writeFile);
Expand Down Expand Up @@ -638,10 +638,7 @@ class Config {
);
this.isFirstTime = true;
this.bootCount = 0;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Manual,
);
sendAnalytics(InstallActionTypes.InstallCompleted, InstallTypes.Manual);
return;
}

Expand All @@ -653,10 +650,7 @@ class Config {
await this.setUpFirstTimeLaunch();
// Skip welcome screen
this.isFirstTime = false;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Auto,
);
sendAnalytics(InstallActionTypes.InstallCompleted, InstallTypes.Auto);
return;
}

Expand All @@ -670,10 +664,7 @@ class Config {
);
this.isFirstTime = true;
this.bootCount = 0;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Manual,
);
sendAnalytics(InstallActionTypes.InstallCompleted, InstallTypes.Manual);
return;
}
logger.info(
Expand Down
2 changes: 1 addition & 1 deletion src/app/crash-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/app/main-api-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/memory-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/screen-snippet-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 7 additions & 1 deletion src/app/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = [];
}
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/app/window-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/app-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron';
import { IAnalyticsData } from '../app/analytics-handler';
import { IAnalyticsData } from '../app/bi/analytics-handler';
import {
apiCmds,
apiName,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/annotate-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import {
AnalyticsElements,
ScreenSnippetActionTypes,
} from './../../app/analytics-handler';
} from '../../app/bi/analytics-handler';
import {
IDimensions,
IPath,
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/snipping-tool.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 08ffae9

Please sign in to comment.