@@ -2,6 +2,7 @@ import { PostHog } from "posthog-node"
22import * as vscode from "vscode"
33
44import { logger } from "../../utils/logging"
5+ import { getpearAIExports } from "../../activate/registerPearListener"
56
67// This forward declaration is needed to avoid circular dependencies
78export interface ClineProviderInterface {
@@ -38,14 +39,38 @@ export class PostHogClient {
3839 }
3940
4041 private static instance : PostHogClient
41- private client : PostHog
42- private distinctId : string = vscode . env . machineId
43- private telemetryEnabled : boolean = true
44- private providerRef : WeakRef < ClineProviderInterface > | null = null
42+ private readonly client : PostHog
43+ private readonly vscMachineId : string
44+ private pearaiId : string
45+ private telemetryEnabled : boolean
46+ private providerRef : WeakRef < ClineProviderInterface > | null
4547
4648 private constructor ( ) {
47- // TODO: HARDCODED POSTHOG API KEY IS NOT GREAT - SHOULD FIX SOME TIME
49+ this . vscMachineId = vscode . env . machineId
50+ this . pearaiId = this . vscMachineId // Initialize with machine ID as fallback
51+ this . telemetryEnabled = true
52+ this . providerRef = null
4853 this . client = new PostHog ( 'phc_RRjQ4roADRjH6xMbXDUDTA9WLeM5ePPvAJK19w3yj0z' , { host : "https://us.i.posthog.com" } )
54+
55+ // getting the pearai id from the submodule
56+ void this . initializePearAIId ( )
57+ }
58+
59+ private async initializePearAIId ( ) : Promise < void > {
60+ try {
61+ const exports = await getpearAIExports ( )
62+ if ( exports ) {
63+ this . pearaiId = await exports . pearAPI . getUserId ( )
64+ this . client . identify ( {
65+ distinctId : this . pearaiId ,
66+ properties : {
67+ vscMachineId : this . vscMachineId
68+ }
69+ } )
70+ }
71+ } catch ( error ) {
72+ logger . debug ( "Failed to get PearAI exports, using machine ID as fallback" )
73+ }
4974 }
5075
5176 /**
@@ -125,7 +150,7 @@ export class PostHogClient {
125150 }
126151
127152 this . client . capture ( {
128- distinctId : this . distinctId ,
153+ distinctId : this . vscMachineId ,
129154 event : event . event ,
130155 properties : mergedProperties ,
131156 } )
0 commit comments