Skip to content

Commit

Permalink
feat: add analytics info for auto-update (silent update)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Jan 6, 2025
1 parent f708474 commit b8887cd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/suite-analytics/src/types/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export type AppUpdateEvent = {
status: AppUpdateEventStatus;
earlyAccessProgram: boolean;
isPrerelease?: boolean;
isAutoUpdated?: boolean;
};
7 changes: 4 additions & 3 deletions packages/suite-analytics/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export type SuiteAnalyticsEventSuiteReady = {
platformLanguages: string;
autodetectLanguage: boolean;
autodetectTheme: boolean;
desktopOsVersion: string | undefined;
desktopOsName: string | undefined;
desktopOsArchitecture: string | undefined;
desktopOsVersion?: string;
desktopOsName?: string;
desktopOsArchitecture?: string;
isAutomaticUpdateEnabled: boolean;
};
};

Expand Down
10 changes: 5 additions & 5 deletions packages/suite-desktop-ui/src/support/DesktopUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export const DesktopUpdater = ({ children }: DesktopUpdaterProps) => {
const hideWindow = useCallback(() => {
dispatch(setUpdateModalVisibility('hidden'));

const payload = getAppUpdatePayload(
AppUpdateEventStatus.Closed,
desktopUpdate.allowPrerelease,
desktopUpdate.latest,
);
const payload = getAppUpdatePayload({
status: AppUpdateEventStatus.Closed,
earlyAccessProgram: desktopUpdate.allowPrerelease,
updateInfo: desktopUpdate.latest,
});
analytics.report({
type: EventType.AppUpdate,
payload,
Expand Down
36 changes: 27 additions & 9 deletions packages/suite/src/actions/suite/desktopUpdateActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export const checking = (): DesktopUpdateAction => ({ type: DESKTOP_UPDATE.CHECK
export const available = (info: UpdateInfo) => (dispatch: Dispatch, getState: GetState) => {
const { allowPrerelease } = getState().desktopUpdate;

const payload = getAppUpdatePayload(AppUpdateEventStatus.Available, allowPrerelease, info);
const payload = getAppUpdatePayload({
status: AppUpdateEventStatus.Available,
earlyAccessProgram: allowPrerelease,
updateInfo: info,
});
analytics.report({
type: EventType.AppUpdate,
payload,
Expand All @@ -49,7 +53,11 @@ export const notAvailable = (info: UpdateInfo) => (dispatch: Dispatch) => {
export const download = () => (dispatch: Dispatch, getState: GetState) => {
const { latest, allowPrerelease } = getState().desktopUpdate;

const payload = getAppUpdatePayload(AppUpdateEventStatus.Download, allowPrerelease, latest);
const payload = getAppUpdatePayload({
status: AppUpdateEventStatus.Download,
earlyAccessProgram: allowPrerelease,
updateInfo: latest,
});
analytics.report({
type: EventType.AppUpdate,
payload,
Expand All @@ -74,7 +82,11 @@ export const ready = (info: UpdateInfo) => (dispatch: Dispatch, getState: GetSta

// update can fail even if it was downloaded successfully
// TODO: Update successful status from electron layer
const payload = getAppUpdatePayload(AppUpdateEventStatus.Downloaded, allowPrerelease, latest);
const payload = getAppUpdatePayload({
status: AppUpdateEventStatus.Downloaded,
earlyAccessProgram: allowPrerelease,
updateInfo: latest,
});
analytics.report({
type: EventType.AppUpdate,
payload,
Expand All @@ -90,13 +102,15 @@ export const installUpdate =
(_: Dispatch, getState: GetState) => {
const { desktopUpdate } = getState();

const payload = getAppUpdatePayload(
installNow
const payload = getAppUpdatePayload({
status: installNow
? AppUpdateEventStatus.InstallAndRestart
: AppUpdateEventStatus.InstallOnQuit,
desktopUpdate.allowPrerelease,
desktopUpdate.latest,
);
earlyAccessProgram: desktopUpdate.allowPrerelease,
updateInfo: desktopUpdate.latest,
isAutoUpdated: desktopUpdate.isAutomaticUpdateEnabled,
});

analytics.report({
type: EventType.AppUpdate,
payload,
Expand All @@ -122,7 +136,11 @@ export const error = (err: Error) => (dispatch: Dispatch, getState: GetState) =>
if (state !== UpdateState.Checking) {
dispatch(notificationsActions.addToast({ type: 'auto-updater-error', state }));

const payload = getAppUpdatePayload(AppUpdateEventStatus.Error, allowPrerelease, latest);
const payload = getAppUpdatePayload({
status: AppUpdateEventStatus.Error,
earlyAccessProgram: allowPrerelease,
updateInfo: latest,
});
analytics.report({
type: EventType.AppUpdate,
payload,
Expand Down
19 changes: 14 additions & 5 deletions packages/suite/src/utils/suite/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,26 @@ export const getSuiteReadyPayload = async (
windowHeight: getWindowHeight(),
autodetectLanguage: state.suite.settings.autodetect.language,
autodetectTheme: state.suite.settings.autodetect.theme,

isAutomaticUpdateEnabled: state.desktopUpdate.isAutomaticUpdateEnabled,
};
};

export const getAppUpdatePayload = (
status: AppUpdateEvent['status'],
earlyAccessProgram: boolean,
updateInfo?: UpdateInfo,
): AppUpdateEvent => ({
export const getAppUpdatePayload = ({
status,
earlyAccessProgram,
updateInfo,
isAutoUpdated,
}: {
status: AppUpdateEvent['status'];
earlyAccessProgram: boolean;
updateInfo?: UpdateInfo;
isAutoUpdated?: boolean;
}): AppUpdateEvent => ({
fromVersion: process.env.VERSION || '',
toVersion: updateInfo?.version,
status,
earlyAccessProgram,
isPrerelease: updateInfo?.prerelease,
isAutoUpdated,
});

0 comments on commit b8887cd

Please sign in to comment.