mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
0b7b3c77c8
Address review feedback on #4643: install_type and location already answer the funnel questions, so persisting raw clipboard contents adds privacy surface without analytic value (the global writeText hook fires on every programmatic copy, not just CLI buttons). Also remove the never-passed product param. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
46 lines
986 B
TypeScript
46 lines
986 B
TypeScript
import type { PostHog } from "posthog-js";
|
|
|
|
const KNOWN_INSTALL_TYPES = [
|
|
"npx",
|
|
"npm",
|
|
"pnpm",
|
|
"yarn",
|
|
"bun",
|
|
"pip",
|
|
"uv",
|
|
"poetry",
|
|
"cargo",
|
|
"go",
|
|
"docker",
|
|
"curl",
|
|
"brew",
|
|
] as const;
|
|
|
|
export type InstallType = (typeof KNOWN_INSTALL_TYPES)[number] | "code";
|
|
|
|
function inferInstallType(command: string): InstallType {
|
|
const firstToken = command.trim().split(/\s+/)[0]?.toLowerCase();
|
|
if (!firstToken) return "code";
|
|
return (KNOWN_INSTALL_TYPES as readonly string[]).includes(firstToken)
|
|
? (firstToken as InstallType)
|
|
: "code";
|
|
}
|
|
|
|
export type TrackCommandCopyArgs = {
|
|
command: string;
|
|
location?: string;
|
|
};
|
|
|
|
export function trackCommandCopy(
|
|
posthog: PostHog | undefined,
|
|
{ command, location }: TrackCommandCopyArgs,
|
|
) {
|
|
if (!posthog) return;
|
|
const trimmed = command.trim();
|
|
if (!trimmed) return;
|
|
posthog.capture("cli_command_copied", {
|
|
install_type: inferInstallType(trimmed),
|
|
...(location ? { location } : {}),
|
|
});
|
|
}
|