SDA-4290 (Create Install BI analytic events) (#1957)

* SDA-4290 - Create Install BI analytic events

* SDA-4290 - Fix uts
This commit is contained in:
Kiran Niranjan 2023-09-21 18:11:26 +05:30 committed by GitHub
parent 34e86d9603
commit 77c9abdf7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 4 deletions

View File

@ -72,6 +72,10 @@ jest.mock('../src/common/logger', () => {
}; };
}); });
jest.mock('../src/app/auto-update-handler', () => {
return {};
});
describe('child window handle', () => { describe('child window handle', () => {
it('should set open window handler', () => { it('should set open window handler', () => {
const spy = jest.spyOn(webContents, 'setWindowOpenHandler'); const spy = jest.spyOn(webContents, 'setWindowOpenHandler');

View File

@ -4,6 +4,9 @@ import * as path from 'path';
import { IConfig, IGlobalConfig } from '../src/app/config-handler'; import { IConfig, IGlobalConfig } from '../src/app/config-handler';
jest.mock('electron-log'); jest.mock('electron-log');
jest.mock('../src/app/auto-update-handler', () => {
return {};
});
describe('config', () => { describe('config', () => {
const configFileName: string = 'Symphony.config'; const configFileName: string = 'Symphony.config';
@ -75,9 +78,8 @@ describe('config', () => {
configInstance.readUserConfig(); configInstance.readUserConfig();
configInstance.readGlobalConfig(); configInstance.readGlobalConfig();
const configField: IGlobalConfig = configInstance.getGlobalConfigFields( const configField: IGlobalConfig =
fieldMock, configInstance.getGlobalConfigFields(fieldMock);
);
expect(configField.url).toBe('something'); expect(configField.url).toBe('something');
}); });

View File

@ -6,7 +6,8 @@ export interface IAnalyticsData {
| MenuActionTypes | MenuActionTypes
| ScreenSnippetActionTypes | ScreenSnippetActionTypes
| ToastNotificationActionTypes | ToastNotificationActionTypes
| SDAUserSessionActionTypes; | SDAUserSessionActionTypes
| InstallActionTypes;
action_result?: AnalyticsActions; action_result?: AnalyticsActions;
extra_data?: object; extra_data?: object;
} }
@ -43,6 +44,13 @@ export interface ISessionData extends IAnalyticsData {
}; };
} }
export interface IInstallData extends IAnalyticsData {
extra_data?: {
installLocation: string;
installType: string;
};
}
export enum MenuActionTypes { export enum MenuActionTypes {
AUTO_LAUNCH_ON_START_UP = 'auto_launch_on_start_up', AUTO_LAUNCH_ON_START_UP = 'auto_launch_on_start_up',
ALWAYS_ON_TOP = 'always_on_top', ALWAYS_ON_TOP = 'always_on_top',
@ -77,6 +85,24 @@ export enum SDAUserSessionActionTypes {
ForceReload = 'Force_reload', ForceReload = 'Force_reload',
} }
export enum InstallActionTypes {
InstallStarted = 'Install_started',
InstallCompleted = 'Install_completed',
InstallFailed = 'Install_failed',
}
export enum InstallTypes {
Auto = 'auto',
Manual = 'manual',
}
export enum InstallLocationTypes {
PROG_FILES = 'PROG_FILES',
REMOTE = 'REMOTE',
LOCAL = 'LOCAL',
CUSTOM = 'CUSTOM',
}
export enum SDAEndReasonTypes { export enum SDAEndReasonTypes {
Reboot = 'Reboot', Reboot = 'Reboot',
Closed = 'Closed', Closed = 'Closed',
@ -94,6 +120,7 @@ export enum AnalyticsElements {
TOAST_NOTIFICATION = 'toast_notification', TOAST_NOTIFICATION = 'toast_notification',
SDA_CRASH = 'sda_crash', SDA_CRASH = 'sda_crash',
SDA_SESSION = 'sda_session', SDA_SESSION = 'sda_session',
SDA_INSTALL = 'sda_install',
} }
export enum SDACrashProcess { export enum SDACrashProcess {

View File

@ -2,10 +2,19 @@ import { GenericServerOptions } from 'builder-util-runtime';
import electronLog from 'electron-log'; import electronLog from 'electron-log';
import { MacUpdater, NsisUpdater } from 'electron-updater'; import { MacUpdater, NsisUpdater } from 'electron-updater';
import { app } from 'electron';
import { isMac, isWindowsOS } from '../common/env'; import { isMac, isWindowsOS } from '../common/env';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { isUrl } from '../common/utils'; import { isUrl } from '../common/utils';
import { whitelistHandler } from '../common/whitelist-handler'; import { whitelistHandler } from '../common/whitelist-handler';
import {
analytics,
AnalyticsElements,
IInstallData,
InstallActionTypes,
InstallLocationTypes,
InstallTypes,
} from './analytics-handler';
import { config } from './config-handler'; import { config } from './config-handler';
import { retrieveWindowsRegistry } from './registry-handler'; import { retrieveWindowsRegistry } from './registry-handler';
import { EChannelRegistry, RegistryStore } from './stores/registry-store'; import { EChannelRegistry, RegistryStore } from './stores/registry-store';
@ -97,6 +106,7 @@ export class AutoUpdate {
if (!this.isUpdateAvailable) { if (!this.isUpdateAvailable) {
return; return;
} }
this.sendAnalytics(InstallActionTypes.InstallStarted, InstallTypes.Auto);
// Handle update and restart for macOS // Handle update and restart for macOS
if (isMac) { if (isMac) {
windowHandler.setIsAutoUpdating(true); windowHandler.setIsAutoUpdating(true);
@ -169,6 +179,24 @@ export class AutoUpdate {
return updateUrl; 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) => { private updateEventHandler = async (info, eventType: string) => {
const mainWebContents = windowHandler.mainWebContents; const mainWebContents = windowHandler.mainWebContents;
if (mainWebContents && !mainWebContents.isDestroyed()) { if (mainWebContents && !mainWebContents.isDestroyed()) {
@ -253,6 +281,30 @@ 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(); const autoUpdate = new AutoUpdate();

View File

@ -8,9 +8,12 @@ import { isDevEnv, isElectronQA, isLinux, isMac } from '../common/env';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { arrayEquals, filterOutSelectedValues, pick } from '../common/utils'; import { arrayEquals, filterOutSelectedValues, pick } from '../common/utils';
import { import {
InstallActionTypes,
InstallTypes,
SDAEndReasonTypes, SDAEndReasonTypes,
SDAUserSessionActionTypes, SDAUserSessionActionTypes,
} from './analytics-handler'; } from './analytics-handler';
import { autoUpdate } from './auto-update-handler';
import { appStats } from './stats'; import { appStats } from './stats';
const writeFile = util.promisify(fs.writeFile); const writeFile = util.promisify(fs.writeFile);
@ -635,6 +638,10 @@ class Config {
); );
this.isFirstTime = true; this.isFirstTime = true;
this.bootCount = 0; this.bootCount = 0;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Manual,
);
return; return;
} }
@ -646,6 +653,10 @@ class Config {
await this.setUpFirstTimeLaunch(); await this.setUpFirstTimeLaunch();
// Skip welcome screen // Skip welcome screen
this.isFirstTime = false; this.isFirstTime = false;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Auto,
);
return; return;
} }
@ -659,6 +670,10 @@ class Config {
); );
this.isFirstTime = true; this.isFirstTime = true;
this.bootCount = 0; this.bootCount = 0;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Manual,
);
return; return;
} }
logger.info( logger.info(