Skip to content

Commit

Permalink
SDA-4290 - Create Install BI analytic events
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan authored and Kiran Niranjan committed Sep 21, 2023
1 parent 3c8ef9a commit bc2b4b0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/app/analytics-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface IAnalyticsData {
| MenuActionTypes
| ScreenSnippetActionTypes
| ToastNotificationActionTypes
| SDAUserSessionActionTypes;
| SDAUserSessionActionTypes
| InstallActionTypes;
action_result?: AnalyticsActions;
extra_data?: object;
}
Expand Down Expand Up @@ -43,6 +44,13 @@ export interface ISessionData extends IAnalyticsData {
};
}

export interface IInstallData extends IAnalyticsData {
extra_data?: {
installLocation: string;
installType: string;
};
}

export enum MenuActionTypes {
AUTO_LAUNCH_ON_START_UP = 'auto_launch_on_start_up',
ALWAYS_ON_TOP = 'always_on_top',
Expand Down Expand Up @@ -77,6 +85,24 @@ export enum SDAUserSessionActionTypes {
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 {
Reboot = 'Reboot',
Closed = 'Closed',
Expand All @@ -94,6 +120,7 @@ export enum AnalyticsElements {
TOAST_NOTIFICATION = 'toast_notification',
SDA_CRASH = 'sda_crash',
SDA_SESSION = 'sda_session',
SDA_INSTALL = 'sda_install',
}

export enum SDACrashProcess {
Expand Down
52 changes: 52 additions & 0 deletions src/app/auto-update-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ 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 { config } from './config-handler';
import { retrieveWindowsRegistry } from './registry-handler';
import { EChannelRegistry, RegistryStore } from './stores/registry-store';
Expand Down Expand Up @@ -97,6 +106,7 @@ export class AutoUpdate {
if (!this.isUpdateAvailable) {
return;
}
this.sendAnalytics(InstallActionTypes.InstallStarted, InstallTypes.Auto);
// Handle update and restart for macOS
if (isMac) {
windowHandler.setIsAutoUpdating(true);
Expand Down Expand Up @@ -169,6 +179,24 @@ 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 @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/app/config-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { isDevEnv, isElectronQA, isLinux, isMac } from '../common/env';
import { logger } from '../common/logger';
import { arrayEquals, filterOutSelectedValues, pick } from '../common/utils';
import {
InstallActionTypes,
InstallTypes,
SDAEndReasonTypes,
SDAUserSessionActionTypes,
} from './analytics-handler';
import { autoUpdate } from './auto-update-handler';
import { appStats } from './stats';

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

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

Expand All @@ -659,6 +670,10 @@ class Config {
);
this.isFirstTime = true;
this.bootCount = 0;
autoUpdate.sendAnalytics(
InstallActionTypes.InstallCompleted,
InstallTypes.Manual,
);
return;
}
logger.info(
Expand Down

0 comments on commit bc2b4b0

Please sign in to comment.