63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import type { EventProps } from './telemetry-events'
|
|
import type { SetupScriptImportCandidate } from './setup-script-imports'
|
|
|
|
type SetupScriptPromptTelemetry = Omit<EventProps<'setup_script_prompt_shown'>, 'nth_repo_added'>
|
|
type SetupScriptPromptActionTelemetry = Omit<
|
|
EventProps<'setup_script_prompt_action'>,
|
|
'nth_repo_added'
|
|
>
|
|
|
|
export type SetupScriptPromptAction = SetupScriptPromptActionTelemetry['action']
|
|
|
|
export function buildSetupScriptPromptTelemetry({
|
|
candidate,
|
|
hasSharedHooks
|
|
}: {
|
|
candidate: SetupScriptImportCandidate | null
|
|
hasSharedHooks: boolean
|
|
}): SetupScriptPromptTelemetry {
|
|
const base = {
|
|
// Why: the UI now treats package-manager suggestions as detected setup,
|
|
// but the analytics wire value is stable for historical funnels.
|
|
mode: candidate ? 'import_available' : 'configure_needed',
|
|
file_count_bucket: bucketSetupScriptCount(candidate?.files.length ?? 0),
|
|
unsupported_field_count_bucket: bucketSetupScriptCount(
|
|
candidate?.unsupportedFields?.length ?? 0
|
|
),
|
|
has_shared_hooks: hasSharedHooks
|
|
} satisfies SetupScriptPromptTelemetry
|
|
|
|
return candidate ? { ...base, provider: candidate.provider } : base
|
|
}
|
|
|
|
export function buildSetupScriptPromptActionTelemetry({
|
|
action,
|
|
candidate,
|
|
hasSharedHooks,
|
|
editedBeforeSave
|
|
}: {
|
|
action: SetupScriptPromptAction
|
|
candidate: SetupScriptImportCandidate | null
|
|
hasSharedHooks: boolean
|
|
editedBeforeSave?: boolean
|
|
}): SetupScriptPromptActionTelemetry {
|
|
return {
|
|
...buildSetupScriptPromptTelemetry({ candidate, hasSharedHooks }),
|
|
action,
|
|
...(editedBeforeSave !== undefined ? { edited_before_save: editedBeforeSave } : {})
|
|
}
|
|
}
|
|
|
|
function bucketSetupScriptCount(count: number): SetupScriptPromptTelemetry['file_count_bucket'] {
|
|
if (count <= 0) {
|
|
return '0'
|
|
}
|
|
if (count === 1) {
|
|
return '1'
|
|
}
|
|
if (count <= 3) {
|
|
return '2-3'
|
|
}
|
|
return '4+'
|
|
}
|