Skip to content

The Open Standard for Generative UI

Track CLI command copy analytics (#796)

Zahle Khan0777642dbbff
diff --git a/docs/app/(home)/components/Button/Button.tsx b/docs/app/(home)/components/Button/Button.tsx
index b5a42cc27..6715e3f09 100644
--- a/docs/app/(home)/components/Button/Button.tsx
+++ b/docs/app/(home)/components/Button/Button.tsx
@@ -60,6 +60,7 @@ interface ClipboardCommandButtonProps {
copyIconColor?: string;
type?: ButtonType;
onCopyChange?: (copied: boolean) => void;
+ onCopySuccess?: (command: string) => void;
}
export function ClipboardCommandButton({
@@ -72,6 +73,7 @@ export function ClipboardCommandButton({
copyIconColor = "white",
type = "button",
onCopyChange,
+ onCopySuccess,
}: ClipboardCommandButtonProps) {
const [copied, setCopied] = useState(false);
const resetTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
@@ -92,6 +94,7 @@ export function ClipboardCommandButton({
}
setCopied(true);
onCopyChange?.(true);
+ onCopySuccess?.(command);
if (resetTimeoutRef.current) {
clearTimeout(resetTimeoutRef.current);
}
diff --git a/docs/app/(home)/sections/BuildChatSection/BuildChatSection.tsx b/docs/app/(home)/sections/BuildChatSection/BuildChatSection.tsx
index 9fe17319b..96e25639e 100644
--- a/docs/app/(home)/sections/BuildChatSection/BuildChatSection.tsx
+++ b/docs/app/(home)/sections/BuildChatSection/BuildChatSection.tsx
@@ -1,5 +1,6 @@
"use client";
+import { captureCreateCliCommandCopied } from "@/lib/create-cli-copy-analytics";
import { ClipboardCommandButton } from "../../components/Button/Button";
import styles from "./BuildChatSection.module.css";
@@ -7,6 +8,13 @@ import styles from "./BuildChatSection.module.css";
// Sub-components
// ---------------------------------------------------------------------------
+function captureBuildChatCliCopy(command: string) {
+ captureCreateCliCommandCopied(command, {
+ source: "homepage_build_chat",
+ interaction: "primary",
+ });
+}
+
function SectionTitle() {
return <p className={styles.title}>Build a Generative UI chat in minutes</p>;
}
@@ -16,6 +24,7 @@ function CtaButton() {
<div className={styles.ctaWrap}>
<ClipboardCommandButton
command="npx @openuidev/cli@latest create"
+ onCopySuccess={captureBuildChatCliCopy}
className={styles.ctaButton}
iconPosition="start"
>
diff --git a/docs/app/(home)/sections/HeroSection/HeroSection.tsx b/docs/app/(home)/sections/HeroSection/HeroSection.tsx
index 530c720be..3d0eafed5 100644
--- a/docs/app/(home)/sections/HeroSection/HeroSection.tsx
+++ b/docs/app/(home)/sections/HeroSection/HeroSection.tsx
@@ -1,5 +1,6 @@
"use client";
+import { captureCreateCliCommandCopied } from "@/lib/create-cli-copy-analytics";
import { ArrowRight } from "lucide-react";
import { PLATFORMS } from "../../components/PlatformLogos";
import { useTheme } from "next-themes";
@@ -11,6 +12,14 @@ import {
} from "../../components/GitHubButton/GitHubButton";
import styles from "./HeroSection.module.css";
+function capturePrimaryHeroCliCopy(command: string) {
+ captureCreateCliCommandCopied(command, { source: "homepage_hero", interaction: "primary" });
+}
+
+function captureDropdownHeroCliCopy(command: string) {
+ captureCreateCliCommandCopied(command, { source: "homepage_hero", interaction: "dropdown" });
+}
+
export const heroStyles = styles;
// CTAs
@@ -93,6 +102,7 @@ export function NpmButton({ className = "", command }: { className?: string; com
<div className={styles.npmButtonWrapper}>
<ClipboardCommandButton
command={command}
+ onCopySuccess={capturePrimaryHeroCliCopy}
className={`${styles.npmButton} ${className}`.trim()}
iconContainerClassName={styles.npmIconBadge}
copyIconColor="currentColor"
@@ -143,6 +153,7 @@ function CommandDropdownButton({
>
<ClipboardCommandButton
command={command}
+ onCopySuccess={capturePrimaryHeroCliCopy}
className={styles.commandTrigger}
iconContainerClassName={styles.commandTriggerBadge}
copyIconColor="currentColor"
@@ -163,6 +174,7 @@ function CommandDropdownButton({
<ClipboardCommandButton
key={variant.id}
command={variant.command}
+ onCopySuccess={captureDropdownHeroCliCopy}
className={styles.commandMenuItem}
iconContainerClassName={styles.commandMenuItemIcon}
copyIconColor="currentColor"
diff --git a/docs/lib/create-cli-copy-analytics.ts b/docs/lib/create-cli-copy-analytics.ts
new file mode 100644
index 000000000..46be70f9a
--- /dev/null
+++ b/docs/lib/create-cli-copy-analytics.ts
@@ -0,0 +1,57 @@
+import posthog from "posthog-js";
+
+export const CREATE_CLI_COMMAND_COPIED_EVENT = "create_cli_command_copied";
+
+export type CreateCliPackageManager = "pnpm" | "bun" | "yarn" | "npm" | "unknown";
+
+export interface CreateCliCopyAnalyticsContext {
+ source: string;
+ interaction?: string;
+}
+
+interface CreateCliCommandCopiedProperties {
+ package_manager: CreateCliPackageManager;
+ source: string;
+ interaction?: string;
+}
+
+const CREATE_CLI_COMMAND_PATTERN = /@openuidev\/cli(?:@\S+)?\s+create(?:\s|$)/i;
+
+export function getCreateCliPackageManager(command: string): CreateCliPackageManager | null {
+ const normalized = command.trim().replace(/\s+/g, " ");
+ if (!CREATE_CLI_COMMAND_PATTERN.test(normalized)) return null;
+
+ if (/^pnpx\s/i.test(normalized)) return "pnpm";
+ if (/^bunx\s/i.test(normalized)) return "bun";
+ if (/^yarn dlx\s/i.test(normalized)) return "yarn";
+ if (/^npx\s/i.test(normalized)) return "npm";
+ return "unknown";
+}
+
+export function getCreateCliCommandCopiedProperties(
+ command: string,
+ context: CreateCliCopyAnalyticsContext,
+): CreateCliCommandCopiedProperties | null {
+ const packageManager = getCreateCliPackageManager(command);
+ if (!packageManager) return null;
+
+ return {
+ package_manager: packageManager,
+ source: context.source,
+ ...(context.interaction ? { interaction: context.interaction } : {}),
+ };
+}
+
+export function captureCreateCliCommandCopied(
+ command: string,
+ context: CreateCliCopyAnalyticsContext,
+): void {
+ const properties = getCreateCliCommandCopiedProperties(command, context);
+ if (!properties || typeof window === "undefined") return;
+
+ try {
+ posthog.capture(CREATE_CLI_COMMAND_COPIED_EVENT, properties);
+ } catch {
+ // Analytics must never interfere with a successful clipboard action.
+ }
+}