Skip to content

armgit / mapcn

Public Imported from GitHub
0

Beautiful map components. 100% Free, Zero config, one command setup.

TypeScript

update: add analytics event tracking

anmoldcca957d9c34
diff --git a/src/app/(main)/(home)/_components/agent-prompt.tsx b/src/app/(main)/(home)/_components/agent-prompt.tsx
index e934dd6..2f1555e 100644
--- a/src/app/(main)/(home)/_components/agent-prompt.tsx
+++ b/src/app/(main)/(home)/_components/agent-prompt.tsx
@@ -5,6 +5,7 @@ import { Check } from "lucide-react";
import { mapInstallAgentPrompt } from "@/lib/llm-prompts";
import { Button } from "@/components/ui/button";
+import { trackEvent } from "@/lib/events";
export function AgentPrompt() {
const [copied, setCopied] = useState(false);
@@ -14,6 +15,7 @@ export function AgentPrompt() {
await navigator.clipboard.writeText(mapInstallAgentPrompt);
setCopied(true);
setTimeout(() => setCopied(false), 2500);
+ trackEvent({ name: "copy_agent_prompt" });
} catch (error) {
console.error("Failed to copy prompt:", error);
}
diff --git a/src/app/(main)/blocks/_components/block-preview.tsx b/src/app/(main)/blocks/_components/block-preview.tsx
index 99fb94a..4d3bc73 100644
--- a/src/app/(main)/blocks/_components/block-preview.tsx
+++ b/src/app/(main)/blocks/_components/block-preview.tsx
@@ -5,6 +5,7 @@ import { Check, Maximize, Terminal } from "lucide-react";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Button } from "@/components/ui/button";
import { RegistryBlockItem, type FileTree } from "@/lib/blocks";
+import { trackEvent } from "@/lib/events";
import { BlockViewerCode, type HighlightedFile } from "./block-viewer-code";
import { Separator } from "@/components/ui/separator";
import Link from "next/link";
@@ -29,6 +30,7 @@ export function BlockPreview({
await navigator.clipboard.writeText(`npx shadcn@latest add @mapcn/${name}`);
setCopiedType("cli");
setTimeout(() => setCopiedType(null), 2000);
+ trackEvent({ name: "copy_block_cli", properties: { block: name } });
}
return (
diff --git a/src/app/(main)/blocks/_components/block-viewer-code.tsx b/src/app/(main)/blocks/_components/block-viewer-code.tsx
index 5ca6fca..fe11d64 100644
--- a/src/app/(main)/blocks/_components/block-viewer-code.tsx
+++ b/src/app/(main)/blocks/_components/block-viewer-code.tsx
@@ -20,6 +20,7 @@ import {
SidebarProvider,
} from "@/components/ui/sidebar";
import { type FileTree } from "@/lib/blocks";
+import { trackEvent } from "@/lib/events";
export interface HighlightedFile {
path: string;
@@ -192,6 +193,10 @@ function CopyCodeButton() {
await navigator.clipboard.writeText(file.content);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
+ trackEvent({
+ name: "copy_block_code",
+ properties: { file: file.target },
+ });
}}
>
{copied ? <Check /> : <Copy />}
diff --git a/src/app/(main)/docs/_components/install-command.tsx b/src/app/(main)/docs/_components/install-command.tsx
index ad68d47..6f6424d 100644
--- a/src/app/(main)/docs/_components/install-command.tsx
+++ b/src/app/(main)/docs/_components/install-command.tsx
@@ -4,6 +4,7 @@ import { useState } from "react";
import { Check, Copy } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { trackEvent } from "@/lib/events";
interface InstallCommandProps {
/** The shadcn registry item to add, e.g. "@mapcn/map" */
@@ -32,6 +33,10 @@ export function InstallCommand({ name }: InstallCommandProps) {
await navigator.clipboard.writeText(current.command);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
+ trackEvent({
+ name: "copy_install_command",
+ properties: { name, packageManager: active },
+ });
};
return (
diff --git a/src/lib/events.ts b/src/lib/events.ts
new file mode 100644
index 0000000..9efa822
--- /dev/null
+++ b/src/lib/events.ts
@@ -0,0 +1,18 @@
+import { track } from "@vercel/analytics";
+
+type EventName =
+ | "copy_install_command"
+ | "copy_block_cli"
+ | "copy_block_code"
+ | "copy_agent_prompt";
+
+type AllowedPropertyValues = string | number | boolean | null;
+
+export interface Event {
+ name: EventName;
+ properties?: Record<string, AllowedPropertyValues>;
+}
+
+export function trackEvent({ name, properties }: Event): void {
+ track(name, properties);
+}