Skip to content

Commit 5e4cc17

Browse files
Merge pull request #152 from codacy/improve-analytics
feat: add org and provider to telemetry CF-1936
2 parents 87480cb + a4d1102 commit 5e4cc17

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/common/telemetry.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as vscode from 'vscode'
22
import { Analytics } from '@segment/analytics-node'
33
import { EventProperties } from '@segment/analytics-core'
4-
import { User } from '../api/client'
4+
import { Organization, User } from '../api/client'
55
import { SEGMENT_WRITE_KEY } from '../env-secrets'
66
import { v4 as uuidv4 } from 'uuid'
77

88
class TelemetryClient {
99
private analytics: Analytics | undefined
1010
private userId: string | undefined
1111
private anonymousId: string | undefined
12+
private organization: Organization | undefined
1213

1314
constructor() {
1415
if (SEGMENT_WRITE_KEY) {
@@ -25,10 +26,11 @@ class TelemetryClient {
2526
}
2627
}
2728

28-
public identify(user: User) {
29+
public identify(user: User, organization?: Organization) {
2930
if (!vscode.env.isTelemetryEnabled || !this.analytics || !this.anonymousId) return
3031

3132
this.userId = user.id.toString()
33+
this.organization = organization
3234

3335
this.analytics.identify({
3436
userId: this.userId,
@@ -49,6 +51,9 @@ class TelemetryClient {
4951
properties: {
5052
ide: vscode.env.appName.toLowerCase(),
5153
os: process.platform,
54+
organization: this.organization?.name,
55+
provider: this.organization?.provider,
56+
organization_id: this.organization?.identifier,
5257
...properties,
5358
},
5459
})

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export async function activate(context: vscode.ExtensionContext) {
269269
initializeApi()
270270

271271
Account.current().then((user) => {
272-
if (user) Telemetry.identify(user)
272+
if (user) Telemetry.identify(user, codacyCloud.organization)
273273
})
274274

275275
if (gitProvider?.repositories.length) {

src/git/CodacyCloud.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ export class CodacyCloud implements vscode.Disposable {
576576
return this._params
577577
}
578578

579+
get organization() {
580+
return this._organization?.organization
581+
}
582+
579583
get lastAnalysedCommit() {
580584
return this._repository?.lastAnalysedCommit
581585
}

0 commit comments

Comments
 (0)