Files
copilotkit__copilotkit/docs/lib/track-command-copy.ts
Benjamin Taylor 0b7b3c77c8 refactor(docs): drop command body and unused product param from copy tracking
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>
2026-05-04 19:07:04 -05:00

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 } : {}),
});
}