Implement setting telemetry

This commit is contained in:
Benjamin Lu
2025-10-31 23:13:20 -07:00
parent 9197119ed8
commit f2952e9ef2
3 changed files with 59 additions and 2 deletions

View File

@@ -4,9 +4,11 @@ import { compare, valid } from 'semver'
import { ref } from 'vue'
import type { SettingParams } from '@/platform/settings/types'
import { useTelemetry } from '@/platform/telemetry'
import type { Settings } from '@/schemas/apiSchema'
import { api } from '@/scripts/api'
import { app } from '@/scripts/app'
import { useDialogStore } from '@/stores/dialogStore'
import type { TreeNode } from '@/types/treeExplorerTypes'
export const getSettingInfo = (setting: SettingParams) => {
@@ -73,6 +75,37 @@ export const useSettingStore = defineStore('setting', () => {
onChange(settingsById.value[key], newValue, oldValue)
settingValues.value[key] = newValue
await api.storeSetting(key, newValue)
try {
const dialogStore = useDialogStore()
if (dialogStore.isDialogOpen('global-settings')) {
const telemetry = useTelemetry()
const param = settingsById.value[key]
const { category, subCategory } = getSettingInfo(
param ??
({
id: String(key)
} as unknown as SettingParams)
)
const inputType = (() => {
const type = param?.type
if (!type) return undefined
return typeof type === 'function' ? 'custom' : String(type)
})()
telemetry?.trackSettingChanged({
setting_id: String(key),
input_type: inputType,
category,
sub_category: subCategory,
previous_value: oldValue,
new_value: newValue
})
}
} catch (err) {
console.error('Failed to track setting change', err)
}
}
/**

View File

@@ -7,7 +7,6 @@ import { app } from '@/scripts/app'
import { useNodeDefStore } from '@/stores/nodeDefStore'
import { NodeSourceType } from '@/types/nodeSource'
import { reduceAllNodes } from '@/utils/graphTraversalUtil'
import { normalizeSurveyResponses } from '../../utils/surveyNormalization'
import type {
AuthMetadata,
@@ -19,18 +18,20 @@ import type {
NodeSearchResultMetadata,
PageVisibilityMetadata,
RunButtonProperties,
SettingChangedMetadata,
SurveyResponses,
TabCountMetadata,
TelemetryEventName,
TelemetryEventProperties,
TelemetryProvider,
TemplateFilterMetadata,
TemplateLibraryMetadata,
TemplateLibraryClosedMetadata,
TemplateLibraryMetadata,
TemplateMetadata,
WorkflowImportMetadata
} from '../../types'
import { TelemetryEvents } from '../../types'
import { normalizeSurveyResponses } from '../../utils/surveyNormalization'
interface QueuedEvent {
eventName: TelemetryEventName
@@ -282,6 +283,10 @@ export class MixpanelTelemetryProvider implements TelemetryProvider {
this.trackEvent(TelemetryEvents.EXECUTION_SUCCESS, metadata)
}
trackSettingChanged(metadata: SettingChangedMetadata): void {
this.trackEvent(TelemetryEvents.SETTING_CHANGED, metadata)
}
getExecutionContext(): ExecutionContext {
const workflowStore = useWorkflowStore()
const templatesStore = useWorkflowTemplatesStore()

View File

@@ -159,6 +159,18 @@ export interface TabCountMetadata {
tab_count: number
}
/**
* Settings change metadata
*/
export interface SettingChangedMetadata {
setting_id: string
input_type?: string
category?: string
sub_category?: string
previous_value?: unknown
new_value?: unknown
}
/**
* Node search metadata
*/
@@ -239,6 +251,9 @@ export interface TelemetryProvider {
trackWorkflowExecution(): void
trackExecutionError(metadata: ExecutionErrorMetadata): void
trackExecutionSuccess(metadata: ExecutionSuccessMetadata): void
// Settings events
trackSettingChanged(metadata: SettingChangedMetadata): void
}
/**
@@ -293,6 +308,9 @@ export const TelemetryEvents = {
// Template Filter Analytics
TEMPLATE_FILTER_CHANGED: 'app:template_filter_changed',
// Settings
SETTING_CHANGED: 'app:setting_changed',
// Execution Lifecycle
EXECUTION_START: 'execution_start',
EXECUTION_ERROR: 'execution_error',
@@ -322,3 +340,4 @@ export type TelemetryEventProperties =
| NodeSearchMetadata
| NodeSearchResultMetadata
| TemplateFilterMetadata
| SettingChangedMetadata