From 075d82fb907286d01c6c184c04d08e00d8f2fbcd Mon Sep 17 00:00:00 2001 From: canvrno <46584286+canvrno@users.noreply.github.com> Date: Fri, 4 Apr 2025 22:23:01 -0700 Subject: [PATCH] ENG-296 - Add telemetry for followup questions (#2661) * initial * added quantity * task.options_ignored * cleanup * cleanup * changeset * Much neater * cleanup --- .changeset/eight-windows-approve.md | 5 +++ src/core/task/index.ts | 10 ++++++ src/services/telemetry/TelemetryService.ts | 38 ++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .changeset/eight-windows-approve.md diff --git a/.changeset/eight-windows-approve.md b/.changeset/eight-windows-approve.md new file mode 100644 index 00000000..daf786ac --- /dev/null +++ b/.changeset/eight-windows-approve.md @@ -0,0 +1,5 @@ +--- +"@cline/extension": patch +--- + +Telemetry added for when users click AI-generated options/questions, or if they ignore them. Also tracks the number of options that were displayed. diff --git a/src/core/task/index.ts b/src/core/task/index.ts index aa518a44..93f310f9 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -2649,6 +2649,9 @@ export class Task { }) } + // Store the number of options for telemetry + const options = parsePartialArrayString(optionsRaw || "[]") + const { text, images } = await this.ask("followup", JSON.stringify(sharedMessage), false) // Check if options contains the text response @@ -2662,9 +2665,11 @@ export class Task { selected: text, } satisfies ClineAskQuestion) await this.saveClineMessagesAndUpdateHistory() + telemetryService.captureOptionSelected(this.taskId, options.length, "act") } } else { // Option not selected, send user feedback + telemetryService.captureOptionsIgnored(this.taskId, options.length, "act") await this.say("user_feedback", text ?? "", images) } @@ -2705,6 +2710,9 @@ export class Task { // }) // } + // Store the number of options for telemetry + const options = parsePartialArrayString(optionsRaw || "[]") + this.isAwaitingPlanResponse = true let { text, images } = await this.ask("plan_mode_respond", JSON.stringify(sharedMessage), false) this.isAwaitingPlanResponse = false @@ -2725,10 +2733,12 @@ export class Task { selected: text, } satisfies ClinePlanModeResponse) await this.saveClineMessagesAndUpdateHistory() + telemetryService.captureOptionSelected(this.taskId, options.length, "plan") } } else { // Option not selected, send user feedback if (text || images?.length) { + telemetryService.captureOptionsIgnored(this.taskId, options.length, "plan") await this.say("user_feedback", text ?? "", images) } } diff --git a/src/services/telemetry/TelemetryService.ts b/src/services/telemetry/TelemetryService.ts index 6651dc12..4c0c6f81 100644 --- a/src/services/telemetry/TelemetryService.ts +++ b/src/services/telemetry/TelemetryService.ts @@ -28,6 +28,10 @@ class PostHogClient { TOKEN_USAGE: "task.tokens", // Tracks switches between plan and act modes MODE_SWITCH: "task.mode", + // Tracks when users select an option from AI-generated followup questions + OPTION_SELECTED: "task.option_selected", + // Tracks when users type a custom response instead of selecting an option from AI-generated followup questions + OPTIONS_IGNORED: "task.options_ignored", // Tracks usage of the git-based checkpoint system (shadow_git_initialized, commit_created, branch_created, branch_deleted_active, branch_deleted_inactive, restored) CHECKPOINT_USED: "task.checkpoint_used", // Tracks when tools (like file operations, commands) are used @@ -457,6 +461,40 @@ class PostHogClient { }) } + /** + * Records when a user selects an option from AI-generated followup questions + * @param taskId Unique identifier for the task + * @param qty The quantity of options that were presented + * @param mode The mode in which the option was selected ("plan" or "act") + */ + public captureOptionSelected(taskId: string, qty: number, mode: "plan" | "act") { + this.capture({ + event: PostHogClient.EVENTS.TASK.OPTION_SELECTED, + properties: { + taskId, + qty, + mode, + }, + }) + } + + /** + * Records when a user types a custom response instead of selecting one of the AI-generated followup questions + * @param taskId Unique identifier for the task + * @param qty The quantity of options that were presented + * @param mode The mode in which the custom response was provided ("plan" or "act") + */ + public captureOptionsIgnored(taskId: string, qty: number, mode: "plan" | "act") { + this.capture({ + event: PostHogClient.EVENTS.TASK.OPTIONS_IGNORED, + properties: { + taskId, + qty, + mode, + }, + }) + } + public isTelemetryEnabled(): boolean { return this.telemetryEnabled }