Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.
TypeScript
Enhance landing page analytics with CTA event tracking
Lewis Carhart48013be91cb4
diff --git a/apps/app/components/landing/analytics.tsx b/apps/app/components/landing/analytics.tsxindex 3a64013e..67ff6a67 100644--- a/apps/app/components/landing/analytics.tsx+++ b/apps/app/components/landing/analytics.tsx@@ -8,6 +8,8 @@ import {import { useMountEffect } from "@crm/ui/hooks/use-mount-effect";import { analyticsAllowed } from "@/lib/analytics";+export type CtaLocation = "hero" | "closing";+export function LandingAnalytics() {useMountEffect(() => {if (!analyticsAllowed(window.location.hostname)) return;@@ -25,3 +27,17 @@ export function LandingAnalytics() {return null;}++export function captureLanding(+ event: "setup_prompt_copied" | "github_star_clicked",+ location: CtaLocation,+): void {+ if (typeof window === "undefined") return;+ if (!analyticsAllowed(window.location.hostname)) return;++ import("posthog-js")+ .then(({ default: posthog }) => {+ posthog.capture(event, { cta_location: location });+ })+ .catch(() => {});+}diff --git a/apps/app/components/landing/closing-cta.tsx b/apps/app/components/landing/closing-cta.tsxindex 1bd4f220..40d05100 100644--- a/apps/app/components/landing/closing-cta.tsx+++ b/apps/app/components/landing/closing-cta.tsx@@ -10,8 +10,8 @@ export function ClosingCta() {</h2><div className="flex flex-wrap items-center justify-center gap-3">- <SetupPromptButton />- <GitHubStarButton />+ <SetupPromptButton location="closing" />+ <GitHubStarButton location="closing" /></div></div></section>diff --git a/apps/app/components/landing/github-star-button.tsx b/apps/app/components/landing/github-star-button.tsxindex 35cc67f3..8ff337d2 100644--- a/apps/app/components/landing/github-star-button.tsx+++ b/apps/app/components/landing/github-star-button.tsx@@ -1,11 +1,19 @@+"use client";+import GitHubLogo from "@crm/ui/components/brand-logos/github";import { Button } from "@crm/ui/components/button";+import { type CtaLocation, captureLanding } from "./analytics";import { REPO_STARS, REPO_URL } from "./links";-export function GitHubStarButton() {+export function GitHubStarButton({ location }: { location: CtaLocation }) {return (<Button variant="outline-ghost" size="xl" asChild>- <a href={REPO_URL} target="_blank" rel="noreferrer">+ <a+ href={REPO_URL}+ target="_blank"+ rel="noreferrer"+ onClick={() => captureLanding("github_star_clicked", location)}+ ><GitHubLogo data-icon="inline-start" className="size-[15px]" />Star on GitHub<span aria-hidden="true" className="h-4 w-px shrink-0 bg-border" />diff --git a/apps/app/components/landing/hero.tsx b/apps/app/components/landing/hero.tsxindex f086c820..3fd11ef6 100644--- a/apps/app/components/landing/hero.tsx+++ b/apps/app/components/landing/hero.tsx@@ -16,8 +16,8 @@ export function Hero() {</p><div className="flex flex-wrap items-center justify-center gap-3 pt-3">- <SetupPromptButton />- <GitHubStarButton />+ <SetupPromptButton location="hero" />+ <GitHubStarButton location="hero" /></div></div></section>diff --git a/apps/app/components/landing/setup-prompt-button.tsx b/apps/app/components/landing/setup-prompt-button.tsxindex 974c94f1..3358ecd7 100644--- a/apps/app/components/landing/setup-prompt-button.tsx+++ b/apps/app/components/landing/setup-prompt-button.tsx@@ -5,6 +5,7 @@ import Copy from "@carbon/icons-react/es/Copy";import ClaudeLogo from "@crm/ui/components/brand-logos/claude";import { Button } from "@crm/ui/components/button";import { useState } from "react";+import { type CtaLocation, captureLanding } from "./analytics";const SETUP_PROMPT ="Set up trycompai/crm — install the dependencies, start Postgres, create my .env, and tell me which keys I still need.";@@ -14,11 +15,12 @@ const SETUP_PROMPT =* where a "Get started" would, because on a repo you fork rather than sign up* for, taking the prompt is what getting started means.*/-export function SetupPromptButton() {+export function SetupPromptButton({ location }: { location: CtaLocation }) {const [copied, setCopied] = useState(false);async function copy() {await navigator.clipboard.writeText(SETUP_PROMPT);+ captureLanding("setup_prompt_copied", location);setCopied(true);setTimeout(() => setCopied(false), 2000);}diff --git a/docs/telemetry.md b/docs/telemetry.mdindex f72781ec..67b63f21 100644--- a/docs/telemetry.md+++ b/docs/telemetry.md@@ -199,9 +199,26 @@ the same two origins, so replay and heatmaps are declined for any other page thakey.**It shares the install's project, key and host**, and the two do not mix: the landing page-sends `$pageview`, `$pageleave`, `$autocapture` and `$web_vitals` about a browser, an install-sends `install_daily` and its funnel about a database. Install events set-`$process_person_profile: false`, so they never become a person and never join one.+sends `$pageview`, `$pageleave`, `$autocapture`, `$web_vitals` and the two CTA events below+about a browser, an install sends `install_daily` and its funnel about a database. Install+events set `$process_person_profile: false`, so they never become a person and never join one.++### The two CTA events++| Event | When |+| --- | --- |+| `setup_prompt_copied` | The setup prompt reached the clipboard — after the write resolves, so a refused clipboard is not counted as a copy |+| `github_star_clicked` | The **Star on GitHub** button was clicked. A click on the way to GitHub, not a star: whether one was given happens on a page we cannot see |++Both carry one property, `cta_location` — `hero` or `closing` — because both buttons appear+twice on the page and which one a stranger reaches is the only interesting thing about them.+Nothing else is attached.++They go through `captureLanding` in `components/landing/analytics.tsx`, behind the same+hostname gate and the same dynamic `import()` as `init`. On any other hostname the SDK is never+fetched, so the click is not sent and then dropped — there is nothing there to send it. Both+sends are fire-and-forget behind a swallowed handler; neither delays the copy or the+navigation.**`anonymize_ips` stays on**, and that costs something here: PostHog drops the address beforegeoip runs, so the landing page has no country, region or city. That setting is what makes the@@ -244,7 +261,7 @@ actually drops it. See `adrs/telemetry.md`.| `apps/api/src/telemetry` | The daily rollup, the funnel sweep, the cron route || `apps/agent/agent/hooks/telemetry.ts` | Tool, turn and session failures || `apps/app/lib/analytics.ts` | The two hostnames the landing page may report from |-| `apps/app/components/landing/analytics.tsx` | The only `posthog-js` import in the repo, behind that gate and a dynamic `import()` |+| `apps/app/components/landing/analytics.tsx` | The only `posthog-js` import in the repo, behind that gate and a dynamic `import()`. `init` on mount, `captureLanding` for the two CTA events |Nothing is instrumented inside `apps/agent/agent/sandbox`, which runs `deny-all` egress bydesign. A capture in there would hang and then fail.