Skip to content

Commit 0dff7f8

Browse files
author
Marcin Mazurek
committed
[DDW-809] Ensure AnalyticsTracker is configured when user consents
1 parent 0a81281 commit 0dff7f8

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

source/renderer/app/analytics/AnalyticsTracker.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ import { MatomoClient } from './MatomoClient';
66
import { NoopAnalyticsClient } from './noopAnalyticsClient';
77

88
export class AnalyticsTracker {
9-
analyticsClient: AnalyticsClient;
9+
#analyticsClient: AnalyticsClient;
1010

1111
constructor(
1212
private environment: Environment,
1313
private localStorage: LocalStorageApi
1414
) {
15-
this.analyticsClient = NoopAnalyticsClient;
15+
this.#analyticsClient = NoopAnalyticsClient;
1616
this.#enableTrackingIfAccepted();
1717
}
1818

1919
async enableTracking() {
20-
this.analyticsClient = new MatomoClient(
20+
this.#analyticsClient = new MatomoClient(
2121
this.environment,
22-
await localStorage.getUserID()
22+
await this.localStorage.getUserID()
2323
);
2424
}
2525

2626
disableTracking() {
27-
this.analyticsClient = NoopAnalyticsClient;
27+
this.#analyticsClient = NoopAnalyticsClient;
2828
}
2929

3030
sendPageNavigationEvent(pageTitle: string) {
31-
return this.analyticsClient.sendPageNavigationEvent(pageTitle);
31+
return this.#analyticsClient.sendPageNavigationEvent(pageTitle);
3232
}
3333

3434
sendEvent(category: string, name: string) {
35-
return this.analyticsClient.sendEvent(category, name);
35+
return this.#analyticsClient.sendEvent(category, name);
3636
}
3737

3838
async #enableTrackingIfAccepted() {

source/renderer/app/analytics/MatomoClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DEV_MODE_SITE_MAP_ID,
88
NETWORK_TO_ANALYTICS_SITE_ID_MAP,
99
} from '../config/analyticsConfig';
10+
import { formattedBytesToSize } from '../utils/formatters';
1011

1112
const CPU_DIMENSION_KEY = 'dimension2';
1213
const RAM_DIMENSION_KEY = 'dimension3';
@@ -33,9 +34,7 @@ export class MatomoClient implements AnalyticsClient {
3334
action_name: pageTitle,
3435
url: this.getAnalyticsURL(),
3536
[CPU_DIMENSION_KEY]: formatCpuInfo(this.environment.cpu),
36-
[RAM_DIMENSION_KEY]: Math.round(
37-
this.environment.ram / 1024 / 1024 / 1024
38-
).toString(),
37+
[RAM_DIMENSION_KEY]: formattedBytesToSize(this.environment.ram),
3938
[OS_DIMENSION_KEY]: this.environment.os,
4039
[VERSION_DIMENSION_KEY]: this.environment.version,
4140
});

source/renderer/app/stores/ProfileStore.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { action, observable, computed, runInAction } from 'mobx';
1+
import { action, computed, observable, runInAction } from 'mobx';
22
import BigNumber from 'bignumber.js';
3-
import { includes, camelCase } from 'lodash';
4-
import axios from 'axios';
5-
import { v4 as uuidv4 } from 'uuid';
3+
import { camelCase, includes } from 'lodash';
64
import { toJS } from '../../../common/utils/helper';
75
import Store from './lib/Store';
86
import Request from './lib/LocalizedRequest';
@@ -15,32 +13,32 @@ import { logger } from '../utils/logging';
1513
import { setStateSnapshotLogChannel } from '../ipc/setStateSnapshotLogChannel';
1614
import { getDesktopDirectoryPathChannel } from '../ipc/getDesktopDirectoryPathChannel';
1715
import { getSystemLocaleChannel } from '../ipc/getSystemLocaleChannel';
16+
import type { Locale } from '../../../common/types/locales.types';
1817
import { LOCALES } from '../../../common/types/locales.types';
1918
import {
2019
compressLogsChannel,
2120
downloadLogsChannel,
2221
getLogsChannel,
2322
} from '../ipc/logs.ipc';
24-
import type { LogFiles, CompressedLogStatus } from '../types/LogTypes';
23+
import type { CompressedLogStatus, LogFiles } from '../types/LogTypes';
2524
import type { StateSnapshotLogParams } from '../../../common/types/logging.types';
26-
import type { Locale } from '../../../common/types/locales.types';
2725
import {
2826
DEFAULT_NUMBER_FORMAT,
2927
NUMBER_FORMATS,
3028
} from '../../../common/types/number.types';
3129
import {
30+
getRequestKeys,
3231
hasLoadedRequest,
3332
isRequestSet,
3433
requestGetter,
3534
requestGetterLocale,
36-
getRequestKeys,
3735
} from '../utils/storesUtils';
3836
import {
39-
NUMBER_OPTIONS,
4037
DATE_ENGLISH_OPTIONS,
4138
DATE_JAPANESE_OPTIONS,
42-
TIME_OPTIONS,
39+
NUMBER_OPTIONS,
4340
PROFILE_SETTINGS,
41+
TIME_OPTIONS,
4442
} from '../config/profileConfig';
4543
import { buildSystemInfo } from '../utils/buildSystemInfo';
4644
import { AnalyticsAcceptanceStatus } from '../analytics/types';
@@ -398,6 +396,12 @@ export default class ProfileStore extends Store {
398396
_setAnalyticsAcceptanceStatus = (status: AnalyticsAcceptanceStatus) => {
399397
this.setAnalyticsAcceptanceRequest.execute(status);
400398
this.getAnalyticsAcceptanceRequest.execute();
399+
400+
if (status === AnalyticsAcceptanceStatus.ACCEPTED) {
401+
this.analytics.enableTracking();
402+
} else if (status === AnalyticsAcceptanceStatus.REJECTED) {
403+
this.analytics.disableTracking();
404+
}
401405
};
402406
_getAnalyticsAcceptance = () => {
403407
this.getAnalyticsAcceptanceRequest.execute();

0 commit comments

Comments
 (0)