Skip to content

Commit 6aeb01d

Browse files
Merge pull request #2586 from RedisInsight/be/feature/RI-4830-Optimize-the-number-of-unique-users-in-telemetry
#RI-4830 Optimize the number of unique users in telemetry
2 parents af1eabb + 3f7806c commit 6aeb01d

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

redisinsight/api/src/modules/analytics/analytics.service.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,34 @@ describe('AnalyticsService', () => {
123123
nonTracking: true,
124124
});
125125

126+
expect(mockAnalyticsTrack).toHaveBeenCalledWith({
127+
anonymousId: NON_TRACKING_ANONYMOUS_ID,
128+
integrations: { Amplitude: { session_id: sessionId } },
129+
event: TelemetryEvents.ApplicationStarted,
130+
properties: {
131+
anonymousId: mockAnonymousId,
132+
buildType: AppType.Electron,
133+
controlNumber: mockControlNumber,
134+
controlGroup: mockControlGroup,
135+
appVersion: mockAppVersion,
136+
},
137+
});
138+
});
139+
it('should send event for non tracking with regular payload', async () => {
140+
settingsService.getAppSettings.mockResolvedValue(mockAppSettings);
141+
142+
await service.sendEvent({
143+
event: TelemetryEvents.ApplicationStarted,
144+
eventData: {},
145+
nonTracking: true,
146+
});
147+
126148
expect(mockAnalyticsTrack).toHaveBeenCalledWith({
127149
anonymousId: mockAnonymousId,
128150
integrations: { Amplitude: { session_id: sessionId } },
129151
event: TelemetryEvents.ApplicationStarted,
130152
properties: {
153+
anonymousId: undefined,
131154
buildType: AppType.Electron,
132155
controlNumber: mockControlNumber,
133156
controlGroup: mockControlGroup,
@@ -190,11 +213,34 @@ describe('AnalyticsService', () => {
190213
nonTracking: true,
191214
});
192215

216+
expect(mockAnalyticsPage).toHaveBeenCalledWith({
217+
anonymousId: NON_TRACKING_ANONYMOUS_ID,
218+
integrations: { Amplitude: { session_id: sessionId } },
219+
name: TelemetryEvents.ApplicationStarted,
220+
properties: {
221+
anonymousId: mockAnonymousId,
222+
buildType: AppType.Electron,
223+
controlNumber: mockControlNumber,
224+
controlGroup: mockControlGroup,
225+
appVersion: mockAppVersion,
226+
},
227+
});
228+
});
229+
it('should send page for non tracking events with regular payload', async () => {
230+
settingsService.getAppSettings.mockResolvedValue(mockAppSettings);
231+
232+
await service.sendPage({
233+
event: TelemetryEvents.ApplicationStarted,
234+
eventData: {},
235+
nonTracking: true,
236+
});
237+
193238
expect(mockAnalyticsPage).toHaveBeenCalledWith({
194239
anonymousId: mockAnonymousId,
195240
integrations: { Amplitude: { session_id: sessionId } },
196241
name: TelemetryEvents.ApplicationStarted,
197242
properties: {
243+
anonymousId: undefined,
198244
buildType: AppType.Electron,
199245
controlNumber: mockControlNumber,
200246
controlGroup: mockControlGroup,

redisinsight/api/src/modules/analytics/analytics.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AppAnalyticsEvents } from 'src/constants';
66
import config from 'src/utils/config';
77
import { SettingsService } from 'src/modules/settings/settings.service';
88

9-
export const NON_TRACKING_ANONYMOUS_ID = 'UNSET';
9+
export const NON_TRACKING_ANONYMOUS_ID = '00000000-0000-0000-0000-000000000001';
1010
const ANALYTICS_CONFIG = config.get('analytics');
1111

1212
export interface ITelemetryEvent {
@@ -73,17 +73,19 @@ export class AnalyticsService {
7373
// The `nonTracking` argument can be set to True to mark an event that doesn't track the specific
7474
// user in any way. When `nonTracking` is True, the event is sent regardless of whether the user's permission
7575
// for analytics is granted or not.
76-
// If permissions not granted anonymousId includes "UNSET" value without any user identifiers.
76+
// If permissions not granted
77+
// anonymousId will includes "00000000-0000-0000-0000-000000000001" value without any user identifiers.
7778
const { event, eventData, nonTracking } = payload;
7879
const isAnalyticsGranted = await this.checkIsAnalyticsGranted();
7980

8081
if (isAnalyticsGranted || nonTracking) {
8182
this.analytics.track({
82-
anonymousId: this.anonymousId,
83+
anonymousId: !isAnalyticsGranted && nonTracking ? NON_TRACKING_ANONYMOUS_ID : this.anonymousId,
8384
integrations: { Amplitude: { session_id: this.sessionId } },
8485
event,
8586
properties: {
8687
...eventData,
88+
anonymousId: !isAnalyticsGranted && nonTracking ? this.anonymousId : undefined,
8789
buildType: this.appType,
8890
controlNumber: this.controlNumber,
8991
controlGroup: this.controlGroup,
@@ -112,10 +114,11 @@ export class AnalyticsService {
112114
if (isAnalyticsGranted || nonTracking) {
113115
this.analytics.page({
114116
name: event,
115-
anonymousId: this.anonymousId,
117+
anonymousId: !isAnalyticsGranted && nonTracking ? NON_TRACKING_ANONYMOUS_ID : this.anonymousId,
116118
integrations: { Amplitude: { session_id: this.sessionId } },
117119
properties: {
118120
...eventData,
121+
anonymousId: !isAnalyticsGranted && nonTracking ? this.anonymousId : undefined,
119122
buildType: this.appType,
120123
controlNumber: this.controlNumber,
121124
controlGroup: this.controlGroup,

0 commit comments

Comments
 (0)