Skip to content

Commit 0c8a77b

Browse files
authored
fix: remove userId COMPASS-7608 (#690)
1 parent 5495195 commit 0c8a77b

File tree

6 files changed

+7
-61
lines changed

6 files changed

+7
-61
lines changed

src/explorer/helpTree.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,7 @@ export default class HelpTree
120120

121121
const atlas = new HelpLinkTreeItem({
122122
title: 'Create Free Atlas Cluster',
123-
url: LINKS.createAtlasCluster(
124-
telemetryUserIdentity?.userId ??
125-
telemetryUserIdentity?.anonymousId ??
126-
''
127-
),
123+
url: LINKS.createAtlasCluster(telemetryUserIdentity?.anonymousId ?? ''),
128124
linkId: 'freeClusterCTA',
129125
iconName: 'atlas',
130126
useRedirect: true,

src/storage/storageController.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,14 @@ export default class StorageController {
9090
}
9191

9292
getUserIdentity() {
93-
const userId = this.get(StorageVariables.GLOBAL_USER_ID);
9493
let anonymousId = this.get(StorageVariables.GLOBAL_ANONYMOUS_ID);
9594

95+
// The anonymousId becomes required with analytics-node v6.
9696
if (!anonymousId) {
9797
anonymousId = uuidv4();
9898
void this.update(StorageVariables.GLOBAL_ANONYMOUS_ID, anonymousId);
9999
}
100100

101-
// Initially, we used `userId` as Segment user identifier, but this usage is being deprecated.
102-
// The `anonymousId` should be used instead.
103-
// We keep sending `userId` to Segment for old users though to preserve their analytics.
104-
if (userId && typeof userId === 'string') {
105-
return {
106-
userId,
107-
anonymousId, // The anonymousId becomes required with analytics-node v6.
108-
};
109-
}
110-
111101
return { anonymousId };
112102
}
113103

src/telemetry/telemetryService.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type PlaygroundTelemetryEventProperties = {
2525

2626
export type SegmentProperties = {
2727
event: string;
28-
userId?: string;
2928
anonymousId: string;
3029
properties: Record<string, any>;
3130
};
@@ -128,7 +127,6 @@ export enum TelemetryEventTypes {
128127
*/
129128
export default class TelemetryService {
130129
_segmentAnalytics?: SegmentAnalytics;
131-
_segmentUserId?: string;
132130
_segmentAnonymousId: string;
133131
_segmentKey?: string; // The segment API write key.
134132

@@ -140,10 +138,9 @@ export default class TelemetryService {
140138
context: vscode.ExtensionContext,
141139
shouldTrackTelemetry?: boolean
142140
) {
143-
const { userId, anonymousId } = storageController.getUserIdentity();
141+
const { anonymousId } = storageController.getUserIdentity();
144142
this._context = context;
145143
this._shouldTrackTelemetry = shouldTrackTelemetry || false;
146-
this._segmentUserId = userId;
147144
this._segmentAnonymousId = anonymousId;
148145
this._segmentKey = this._readSegmentKey();
149146
}
@@ -295,13 +292,6 @@ export default class TelemetryService {
295292
}
296293

297294
getTelemetryUserIdentity() {
298-
if (this._segmentUserId) {
299-
return {
300-
userId: this._segmentUserId,
301-
anonymousId: this._segmentAnonymousId,
302-
};
303-
}
304-
305295
return {
306296
anonymousId: this._segmentAnonymousId,
307297
};

src/test/suite/explorer/helpExplorer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ suite('Help Explorer Test Suite', function () {
4545

4646
assert.strictEqual(atlasHelpItem.label, 'Create Free Atlas Cluster');
4747
assert.strictEqual(atlasHelpItem.url.includes('mongodb.com'), true);
48-
const { userId, anonymousId } =
48+
const { anonymousId } =
4949
mdbTestExtension.testExtensionController._telemetryService.getTelemetryUserIdentity();
5050
assert.strictEqual(
5151
new URL(atlasHelpItem.url).searchParams.get('ajs_aid'),
52-
userId ?? anonymousId
52+
anonymousId
5353
);
5454
assert.strictEqual(atlasHelpItem.iconName, 'atlas');
5555
assert.strictEqual(atlasHelpItem.linkId, 'freeClusterCTA');

src/test/suite/storage/storageController.test.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import assert from 'assert';
2-
import { before } from 'mocha';
3-
import { v4 as uuidv4 } from 'uuid';
42

53
import StorageController, {
64
StorageVariables,
@@ -45,7 +43,7 @@ suite('Storage Controller Test Suite', () => {
4543
);
4644
});
4745

48-
suite('for a new user that does not have anonymousId or userId', () => {
46+
suite('for a new user that does not have anonymousId', () => {
4947
const extensionContextStub = new ExtensionContextStub();
5048
extensionContextStub._globalState = {};
5149
const testStorageController = new StorageController(extensionContextStub);
@@ -55,34 +53,7 @@ suite('Storage Controller Test Suite', () => {
5553
const anonymousId = testStorageController.get(
5654
StorageVariables.GLOBAL_ANONYMOUS_ID
5755
);
58-
const userId = testStorageController.get(StorageVariables.GLOBAL_USER_ID);
5956
assert.deepStrictEqual(userIdentity, { anonymousId });
60-
assert(!userId);
61-
});
62-
});
63-
64-
suite('for an old user that does not have anonymousId but has userId', () => {
65-
const extensionContextStub = new ExtensionContextStub();
66-
extensionContextStub._globalState = {};
67-
const testStorageController = new StorageController(extensionContextStub);
68-
const id = uuidv4();
69-
70-
before(async () => {
71-
await testStorageController.update(
72-
StorageVariables.GLOBAL_USER_ID,
73-
id,
74-
StorageLocation.GLOBAL
75-
);
76-
});
77-
78-
test('getUserIdentity returns userId from the global storage and returns it to telemetry', () => {
79-
const userIdentity = testStorageController.getUserIdentity();
80-
const anonymousId = testStorageController.get(
81-
StorageVariables.GLOBAL_ANONYMOUS_ID
82-
);
83-
const userId = testStorageController.get(StorageVariables.GLOBAL_USER_ID);
84-
assert(userId === id);
85-
assert.deepStrictEqual(userIdentity, { userId, anonymousId });
8657
});
8758
});
8859
});

src/views/webviewController.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ export default class WebviewController {
328328

329329
panel.webview.html = getWebviewContent({
330330
extensionPath,
331-
telemetryUserId:
332-
telemetryUserIdentity.anonymousId || telemetryUserIdentity.userId,
331+
telemetryUserId: telemetryUserIdentity.anonymousId,
333332
webview: panel.webview,
334333
});
335334

0 commit comments

Comments
 (0)