Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.
TypeScript
Add telemetry support and enhance landing page analytics
Lewis Carhart7bff0f4a50c4
diff --git a/apps/agent/agent/hooks/audit.ts b/apps/agent/agent/hooks/audit.tsindex a574b0aa..0a363768 100644--- a/apps/agent/agent/hooks/audit.ts+++ b/apps/agent/agent/hooks/audit.ts@@ -2,12 +2,14 @@ import { db } from "@crm/db";import { defineHook } from "eve/hooks";import { currentFocus } from "../lib/focus";+const CUMULATIVE_DELTAS = new Set(["reasoning.appended"]);+export default defineHook({events: {async "*"(event, ctx) {const id = event.meta?.id;- if (!id) return;+ if (!id || CUMULATIVE_DELTAS.has(event.type)) return;try {await db.agentEvent.createMany({diff --git a/apps/app/app/(landing)/page.tsx b/apps/app/app/(landing)/page.tsxindex 99c59847..8f27656d 100644--- a/apps/app/app/(landing)/page.tsx+++ b/apps/app/app/(landing)/page.tsx@@ -1,5 +1,6 @@import type { Metadata } from "next";import { AgentSection } from "@/components/landing/agent-section";+import { LandingAnalytics } from "@/components/landing/analytics";import { CapabilitiesSection } from "@/components/landing/capabilities-section";import { ClosingCta } from "@/components/landing/closing-cta";import { Hero } from "@/components/landing/hero";@@ -23,6 +24,7 @@ export default function Home() {<CapabilitiesSection /><ClosingCta /><LandingFooter />+ <LandingAnalytics /></div>);}diff --git a/apps/app/components/crm/agent-panel.tsx b/apps/app/components/crm/agent-panel.tsxindex 48edb238..61f2dee7 100644--- a/apps/app/components/crm/agent-panel.tsx+++ b/apps/app/components/crm/agent-panel.tsx@@ -62,6 +62,7 @@ import {composerState,eventsOf,loadThread,+ offlineThread,type Thread as ThreadState,} from "@/lib/agent-session";import {@@ -116,6 +117,7 @@ export function AgentPanel({ record }: { record: AgentRecord }) {}const WORKING_POLL_MS = 3000;+const SETTLED_TTL_MS = 60_000;function ThreadWithHistory({record,@@ -128,30 +130,26 @@ function ThreadWithHistory({}) {const trpc = useTRPC();- const archive = useQuery({- ...trpc.conversations.events.queryOptions({ id: conversation?.id ?? "" }),- enabled: conversation !== null,- staleTime: Number.POSITIVE_INFINITY,- });-const thread = useQuery<ThreadState>({queryKey: ["agent-thread", conversation?.sessionId],- enabled: conversation !== null && !archive.isPending,- staleTime: 0,- refetchOnMount: "always",+ enabled: conversation !== null,+ staleTime: SETTLED_TTL_MS,refetchOnWindowFocus: false,refetchInterval: (query) =>query.state.data?.status === "working" ? WORKING_POLL_MS : false,queryFn: ({ signal }) =>- loadThread(- conversation?.sessionId ?? "",- recordHeader(record),- (archive.data ?? []) as never,- signal,- ),+ loadThread(conversation?.sessionId ?? "", recordHeader(record), signal),+ });++ const offline = thread.data?.status === "offline";++ const archive = useQuery({+ ...trpc.conversations.events.queryOptions({ id: conversation?.id ?? "" }),+ enabled: conversation !== null && offline,+ staleTime: Number.POSITIVE_INFINITY,});- if (conversation && (archive.isPending || thread.isPending))+ if (conversation && (thread.isPending || (offline && archive.isPending)))return <Loading />;return (@@ -159,7 +157,9 @@ function ThreadWithHistory({key={thread.data?.status === "working" ? "working" : "settled"}record={record}conversation={conversation}- thread={thread.data}+ thread={+ offline ? offlineThread((archive.data ?? []) as never) : thread.data+ }onNewThread={onNewThread}/>);diff --git a/apps/app/components/landing/analytics.tsx b/apps/app/components/landing/analytics.tsxnew file mode 100644index 00000000..3a64013e--- /dev/null+++ b/apps/app/components/landing/analytics.tsx@@ -0,0 +1,27 @@+"use client";++import {+ POSTHOG_HOST,+ POSTHOG_KEY,+ POSTHOG_UI_HOST,+} from "@crm/telemetry/project";+import { useMountEffect } from "@crm/ui/hooks/use-mount-effect";+import { analyticsAllowed } from "@/lib/analytics";++export function LandingAnalytics() {+ useMountEffect(() => {+ if (!analyticsAllowed(window.location.hostname)) return;++ import("posthog-js")+ .then(({ default: posthog }) => {+ posthog.init(POSTHOG_KEY, {+ api_host: POSTHOG_HOST,+ ui_host: POSTHOG_UI_HOST,+ defaults: "2026-06-25",+ });+ })+ .catch(() => {});+ });++ return null;+}diff --git a/apps/app/lib/agent-session.ts b/apps/app/lib/agent-session.tsindex e5668d9d..5d59dfbb 100644--- a/apps/app/lib/agent-session.ts+++ b/apps/app/lib/agent-session.ts@@ -30,7 +30,6 @@ export type Thread =export async function loadThread(sessionId: string,headers: Record<string, string>,- archive: readonly MessageStreamEvent[] = [],signal?: AbortSignal,): Promise<Thread> {try {@@ -43,11 +42,17 @@ export async function loadThread(session: snapshot.session,events: snapshot.events,} as Thread;- } catch {- return { status: "offline", events: archive };+ } catch (error) {+ if (signal?.aborted) throw error;++ return { status: "offline", events: [] };}}+export function offlineThread(events: readonly MessageStreamEvent[]): Thread {+ return { status: "offline", events };+}+export function classify(session: SessionState,events: readonly MessageStreamEvent[],diff --git a/apps/app/lib/analytics.ts b/apps/app/lib/analytics.tsnew file mode 100644index 00000000..302ea587--- /dev/null+++ b/apps/app/lib/analytics.ts@@ -0,0 +1,8 @@+export const ANALYTICS_HOSTS: readonly string[] = [+ "trycrm.ai",+ "www.trycrm.ai",+];++export function analyticsAllowed(hostname: string): boolean {+ return ANALYTICS_HOSTS.includes(hostname.trim().toLowerCase());+}diff --git a/apps/app/next.config.ts b/apps/app/next.config.tsindex be560a6c..f3e1834c 100644--- a/apps/app/next.config.ts+++ b/apps/app/next.config.ts@@ -13,7 +13,7 @@ const nextConfig: NextConfig = {NEXT_PUBLIC_API_URL: apiUrl,},- transpilePackages: ["@crm/auth", "@crm/db", "@crm/ui"],+ transpilePackages: ["@crm/auth", "@crm/db", "@crm/telemetry", "@crm/ui"],serverExternalPackages: ["@prisma/client", "@prisma/adapter-pg", "pg"],diff --git a/apps/app/package.json b/apps/app/package.jsonindex 8ddaa67f..35e03a23 100644--- a/apps/app/package.json+++ b/apps/app/package.json@@ -16,6 +16,7 @@"@crm/auth": "workspace:*","@crm/db": "workspace:*","@crm/env": "workspace:*",+ "@crm/telemetry": "workspace:*","@crm/ui": "workspace:*","@tanstack/react-query": "^5.101.2","@trpc/client": "^11.18.0",@@ -27,6 +28,7 @@"next": "16.3.0","next-themes": "^0.4.6","nuqs": "^2.8.9",+ "posthog-js": "^1.413.2","react": "19.2.4","react-dom": "19.2.4","sonner": "^2.0.7"diff --git a/apps/app/test/landing-analytics.spec.ts b/apps/app/test/landing-analytics.spec.tsnew file mode 100644index 00000000..8724381d--- /dev/null+++ b/apps/app/test/landing-analytics.spec.ts@@ -0,0 +1,27 @@+import { describe, expect, it } from "bun:test";+import { analyticsAllowed } from "../lib/analytics";++describe("analyticsAllowed", () => {+ it("allows the two hosts the landing page is served from", () => {+ expect(analyticsAllowed("trycrm.ai")).toBe(true);+ expect(analyticsAllowed("www.trycrm.ai")).toBe(true);+ });++ it("ignores case and surrounding whitespace", () => {+ expect(analyticsAllowed(" TryCRM.ai ")).toBe(true);+ });++ it("refuses a self-hosted install serving the same page", () => {+ expect(analyticsAllowed("crm.acme.com")).toBe(false);+ expect(analyticsAllowed("localhost")).toBe(false);+ });++ it("refuses a preview deployment", () => {+ expect(analyticsAllowed("crm-git-lewis-telemetry.vercel.app")).toBe(false);+ });++ it("refuses a host that merely ends in the marketing domain", () => {+ expect(analyticsAllowed("evil-trycrm.ai")).toBe(false);+ expect(analyticsAllowed("trycrm.ai.attacker.com")).toBe(false);+ });+});diff --git a/bun.lock b/bun.lockindex cc650a2f..b85aff9e 100644--- a/bun.lock+++ b/bun.lock@@ -76,6 +76,7 @@"@crm/auth": "workspace:*","@crm/db": "workspace:*","@crm/env": "workspace:*",+ "@crm/telemetry": "workspace:*","@crm/ui": "workspace:*","@tanstack/react-query": "^5.101.2","@trpc/client": "^11.18.0",@@ -87,6 +88,7 @@"next": "16.3.0","next-themes": "^0.4.6","nuqs": "^2.8.9",+ "posthog-js": "^1.413.2","react": "19.2.4","react-dom": "19.2.4","sonner": "^2.0.7",@@ -529,6 +531,8 @@"@paralleldrive/cuid2": ["@paralleldrive/[email protected]", "", { "dependencies": { "@noble/hashes": "^1.1.5" } }, "sha512-XO7cAxhnTZl0Yggq6jOgjiOHhbgcO4NqFqwSmQpjK3b6TEE6Uj/jfSk6wzYyemh3+I0sHirKSetjQwn5cZktFw=="],+ "@posthog/browser-common": ["@posthog/[email protected]", "", { "dependencies": { "@posthog/core": "^1.46.8", "@posthog/types": "^1.402.0" } }, "sha512-W9DCGVks15docUMPvJ2nd8NS16Gn74bsGWuaeg31beEKFSjdW8wvnQ1ETY6WSql5pYxZb3GdJmEUZVVstKSrBQ=="],+"@posthog/core": ["@posthog/[email protected]", "", { "dependencies": { "@posthog/types": "^1.401.1" } }, "sha512-WQTSwlFhsWk09xngTimHiTyhFU8QZHFZEGSm+6brY3acwYdvTLcTxpIhgl/qOCgn/XoqlCFTZqU1ldWLxNntfA=="],"@posthog/types": ["@posthog/[email protected]", "", {}, "sha512-4PZ9wMYI8m8AqJuZ9YR1IAHGVtSnYbBVBgTevrKpzZbcSe/OUwhEV2Ks//rJh/L8eMTU8R5DrD4D/hlrOwaAiQ=="],@@ -1137,6 +1141,8 @@"cookiejar": ["[email protected]", "", {}, "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw=="],+ "core-js": ["[email protected]", "", {}, "sha512-BRWgOLKkFeCgRudR6zrs8p9XJZcE14grzKMMssoYrk6krtuEZ7MTKPIY5RzOnqsEKIR9kst7wNzphttraT+Yqw=="],+"cors": ["[email protected]", "", { "dependencies": { "object-assign": "^4", "vary": "^1" } }, "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw=="],"cose-base": ["[email protected]", "", { "dependencies": { "layout-base": "^1.0.0" } }, "sha512-s9whTXInMSgAp/NVXVNuVxVKzGH2qck3aQlVHxDCdAEPgtMKwc4Wq6/QKhgdEdgbLSi9rBTAcPoRa6JpiG4ksg=="],@@ -1381,6 +1387,8 @@"fdir": ["[email protected]", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="],+ "fflate": ["[email protected]", "", {}, "sha512-zdxgIEddhfsyCaWpJ2SdXEP8ZMrKJ6+5jl4OupODcywU0IhRk6gdXuVGcPICyfx2H97hVK7xmJtRLPjkxAX8Vw=="],+"figures": ["[email protected]", "", { "dependencies": { "is-unicode-supported": "^2.0.0" } }, "sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg=="],"file-type": ["[email protected]", "", { "dependencies": { "@tokenizer/inflate": "^0.4.1", "strtok3": "^10.3.4", "token-types": "^6.1.1", "uint8array-extras": "^1.4.0" } }, "sha512-Ievi/yy8DS3ygGvT47PjSfdFoX+2isQueoYP1cntFW1JLYAuS4GD7NUPGg4zv2iZfV52uDyk5w5Z0TdpRS6Q1g=="],@@ -1925,10 +1933,14 @@"postgres-interval": ["[email protected]", "", { "dependencies": { "xtend": "^4.0.0" } }, "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ=="],+ "posthog-js": ["[email protected]", "", { "dependencies": { "@posthog/browser-common": "^0.4.0", "@posthog/core": "^1.46.8", "@posthog/types": "^1.402.1", "core-js": "^3.49.0", "dompurify": "^3.4.12", "fflate": "^0.4.8", "preact": "^10.29.3", "query-selector-shadow-dom": "^1.0.1", "web-vitals": "^5.3.0", "web-vitals-soft-navs": "npm:[email protected]" } }, "sha512-LddTVMdYFd0jB+p5h3ZHcho9mWNjgKn9QySCQt74iISKrmC3b7KzW2Q7W7aOF6m/NwK7NubIHqLujCER64gSRw=="],+"posthog-node": ["[email protected]", "", { "dependencies": { "@posthog/core": "^1.46.8" }, "peerDependencies": { "rxjs": "^7.0.0" }, "optionalPeers": ["rxjs"] }, "sha512-YIH82XV24aa1nnVph1ndiW/vBN2QDIKlrHNEJcmAYutMGeoGC4WeEefg7O5aD3dDcO5dzociy8sVwXq4tNDYsQ=="],"powershell-utils": ["[email protected]", "", {}, "sha512-dM0jVuXJPsDN6DvRpea484tCUaMiXWjuCn++HGTqUWzGDjv5tZkEZldAJ/UMlqRYGFrD/etByo4/xOuC/snX2A=="],+ "preact": ["[email protected]", "", { "peerDependencies": { "preact-render-to-string": ">=5" }, "optionalPeers": ["preact-render-to-string"] }, "sha512-ej2aVZ+vZ8WO7tvlQWRM9N63A0KzF9q4mWJfDUHgYaIofWY9hu74QdnQrjoPMmZi2/nZ5gN0bJCQF49xQqx09Q=="],+"prebuild-install": ["[email protected]", "", { "dependencies": { "detect-libc": "^2.0.0", "expand-template": "^2.0.3", "github-from-package": "0.0.0", "minimist": "^1.2.3", "mkdirp-classic": "^0.5.3", "napi-build-utils": "^2.0.0", "node-abi": "^3.3.0", "pump": "^3.0.0", "rc": "^1.2.7", "simple-get": "^4.0.0", "tar-fs": "^2.0.0", "tunnel-agent": "^0.6.0" }, "bin": { "prebuild-install": "bin.js" } }, "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug=="],"prettier": ["[email protected]", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-OpN0zzVdiaiAhxpuuj5efpIS4sY9j7bY6uR5mnj5yPzGkdkjNKSJeUThPb60Jw29QuAZgA4o+/iB49kFiaBX6g=="],@@ -1953,6 +1965,8 @@"qs": ["[email protected]", "", { "dependencies": { "es-define-property": "^1.0.1", "side-channel": "^1.1.1" } }, "sha512-O9gl3zCl5h5blw1KGUzQKhA5oUXSl8rwUIM5o0S3nCXMliSvy5Dzx7/DJcI+SwgICv+IneSZwhBh1oSyEHA71A=="],+ "query-selector-shadow-dom": ["[email protected]", "", {}, "sha512-lT5yCqEBgfoMYpf3F2xQRK7zEr1rhIIZuceDK6+xRkJQ4NMbHTwXqk4NkwDwQMNqXgG9r9fyHnzwNVs6zV5KRw=="],+"queue-microtask": ["[email protected]", "", {}, "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="],"radix-ui": ["[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.7", "@radix-ui/react-accessible-icon": "1.1.15", "@radix-ui/react-accordion": "1.2.20", "@radix-ui/react-alert-dialog": "1.1.23", "@radix-ui/react-arrow": "1.1.15", "@radix-ui/react-aspect-ratio": "1.1.15", "@radix-ui/react-avatar": "1.2.6", "@radix-ui/react-checkbox": "1.3.11", "@radix-ui/react-collapsible": "1.1.20", "@radix-ui/react-collection": "1.1.15", "@radix-ui/react-compose-refs": "1.1.5", "@radix-ui/react-context": "1.2.2", "@radix-ui/react-context-menu": "2.3.7", "@radix-ui/react-dialog": "1.1.23", "@radix-ui/react-direction": "1.1.4", "@radix-ui/react-dismissable-layer": "1.1.19", "@radix-ui/react-dropdown-menu": "2.1.24", "@radix-ui/react-focus-guards": "1.1.6", "@radix-ui/react-focus-scope": "1.1.16", "@radix-ui/react-form": "0.1.16", "@radix-ui/react-hover-card": "1.1.23", "@radix-ui/react-label": "2.1.15", "@radix-ui/react-menu": "2.1.24", "@radix-ui/react-menubar": "1.1.24", "@radix-ui/react-navigation-menu": "1.2.22", "@radix-ui/react-one-time-password-field": "0.1.16", "@radix-ui/react-password-toggle-field": "0.1.11", "@radix-ui/react-popover": "1.1.23", "@radix-ui/react-popper": "1.3.7", "@radix-ui/react-portal": "1.1.17", "@radix-ui/react-presence": "1.1.10", "@radix-ui/react-primitive": "2.1.10", "@radix-ui/react-progress": "1.1.16", "@radix-ui/react-radio-group": "1.4.7", "@radix-ui/react-roving-focus": "1.1.19", "@radix-ui/react-scroll-area": "1.2.18", "@radix-ui/react-select": "2.3.7", "@radix-ui/react-separator": "1.1.15", "@radix-ui/react-slider": "1.4.7", "@radix-ui/react-slot": "1.3.3", "@radix-ui/react-switch": "1.3.7", "@radix-ui/react-tabs": "1.1.21", "@radix-ui/react-toast": "1.2.23", "@radix-ui/react-toggle": "1.1.18", "@radix-ui/react-toggle-group": "1.1.19", "@radix-ui/react-toolbar": "1.1.19", "@radix-ui/react-tooltip": "1.2.16", "@radix-ui/react-use-callback-ref": "1.1.4", "@radix-ui/react-use-controllable-state": "1.2.6", "@radix-ui/react-use-effect-event": "0.0.5", "@radix-ui/react-use-escape-keydown": "1.1.5", "@radix-ui/react-use-is-hydrated": "0.1.3", "@radix-ui/react-use-layout-effect": "1.1.4", "@radix-ui/react-use-size": "1.1.4", "@radix-ui/react-visually-hidden": "1.2.11" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-QBdhh1arIEUvPC0dQ5+nwWAxt7+N+oP/9jPwjJkGFoSk/sqxg32gJtSXGtFh8frAIcS6oC9cx2Q+7KYCQLOAeA=="],@@ -2271,6 +2285,10 @@"web-namespaces": ["[email protected]", "", {}, "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ=="],+ "web-vitals": ["[email protected]", "", {}, "sha512-q6LWsLatGYZp5VGBIOvbTj6JBV2nOmC8KvWztXBmwJcfFAzhwKwbOxhUH306XY3CcaZDUlSmSuNPBsCn0bFu+g=="],++ "web-vitals-soft-navs": ["[email protected]", "", {}, "sha512-Guaibvy/+uNtL6Bsu4jmMJGzuSl91oeRH5iO9pPRbYftnFUr3yqT1TUNX/OE4o9HexuEMU3Kb/Wg7iKhlffZUA=="],+"which": ["[email protected]", "", { "dependencies": { "isexe": "^3.1.1" }, "bin": { "node-which": "bin/which.js" } }, "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg=="],"wrap-ansi": ["[email protected]", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="],diff --git a/docs/agent-panel.md b/docs/agent-panel.mdindex 7eb2538c..49b3d876 100644--- a/docs/agent-panel.md+++ b/docs/agent-panel.md@@ -12,6 +12,20 @@ claim minted, the field a conversation is filed under, the empty-thread question- **The token is the authority on whether a message can be sent**, not our reading ofthe events.- **`streamIndex: 0` on resume** — the saved index is where the last *reader* stopped.+- **The snapshot is cached for a minute, not refetched on every mount.** A settled+ thread cannot change under us — `ready` is waiting on the rep, `ended` is over — and+ the snapshot is the whole session from index 0, tens of megabytes on a real thread.+ A live thread stays live through `refetchInterval`, which ignores `staleTime`.+- **`loadThread` rethrows an abort.** Swallowing it caches a false `offline` for the+ life of the `staleTime`; only a genuinely unreachable agent may return one.+- **The archive is fetched only when the snapshot fails.** It is the offline fallback+ and nothing else, so loading it up front bought a serial round trip on every open.+ Nothing renders until it lands — `useEveAgent` reads `initialEvents` once, at mount.+- **The audit hook does not archive `reasoning.appended`.** Every delta carries+ `reasoningSoFar`, the whole reasoning to that point, so the archive grew as the+ square of the tokens — one insert per token, 90% of `AgentEvent`, for events the+ transcript never renders. `reasoning.completed` still lands. eve's durable stream+ keeps its own copy either way; this is only what we file.- **Quiet for 90 seconds is over, not working** — restarted agents leave sessions withno closing boundary, which would lock the thread forever.- **An unreachable agent is `offline`, not `working`** — fall back to the `AgentEvent`diff --git a/docs/environment.md b/docs/environment.mdindex a77b98d2..b9345b55 100644--- a/docs/environment.md+++ b/docs/environment.md@@ -136,11 +136,14 @@ says who is internal — two sources is how a colleague becomes a lead), **no`CRM_TELEMETRY_DISABLED="1"` — or `DO_NOT_TRACK=1`, honoured identically — and nothingis sent. No client is constructed, so there is no queue waiting to flush later.-- **Server side only**, `posthog-node` in the API and the agent. **There is no- `posthog-js` in this repo** and there must not be: autocapture on a CRM would- lift contact names and deal amounts out of somebody else's database.+- **Server side only**, `posthog-node` in the API and the agent. **`posthog-js`+ appears once, on the `trycrm.ai` landing page**, and nowhere a record can be+ reached: autocapture on a CRM would lift contact names and deal amounts out of+ somebody else's database. That one import is gated on+ `window.location.hostname`, not on `IS_MARKETING` — turning the landing page on+ for your own domain never loads it. `docs/telemetry.md`.- **There is no variable for the destination.** The project key and host are- constants in `packages/telemetry/src/client.ts`. A `phc_` key is write-only —+ constants in `packages/telemetry/src/project.ts`. A `phc_` key is write-only —it can send events and read nothing back — so making it configurable wouldonly imply it were a secret. Edit the constants to point somewhere else.- **The install ID is a row, not a file** — `install`, one row, UUID written bydiff --git a/docs/telemetry.md b/docs/telemetry.mdindex c2553dde..f72781ec 100644--- a/docs/telemetry.md+++ b/docs/telemetry.md@@ -8,17 +8,20 @@ restart. This file is the full account of what is sent; there is no settings pagthis is the thing to read.**Where it goes** is not configurable and deliberately so: the project key and host are constants-in `packages/telemetry/src/client.ts`. A `phc_` key is write-only — it sends events and reads+in `packages/telemetry/src/project.ts`. A `phc_` key is write-only — it sends events and readsnothing back — so a variable would only have made a public identifier look like a secret. Point-a fork somewhere else by editing those two constants. Nothing is sent while `NODE_ENV` is+a fork somewhere else by editing that file. Nothing is sent while `NODE_ENV` is`test`, so a test run cannot emit.## The shape of it-- **Server side only.** `posthog-node` in `apps/api` and `apps/agent`. There is no `posthog-js`- in this repo, no autocapture, no session replay and nothing at all in `apps/app`. Autocapture- on a CRM would lift contact names, email addresses, company domains and deal amounts out of- your database; the simplest way not to hold that is not to collect it.+- **Server side only, in everything you run.** `posthog-node` in `apps/api` and `apps/agent`.+ No autocapture, no session replay and nothing client-side anywhere a record can be reached.+ Autocapture on a CRM would lift contact names, email addresses, company domains and deal+ amounts out of your database; the simplest way not to hold that is not to collect it. The+ single exception is the marketing site at `trycrm.ai`, which is a web page and not an+ install — **The landing page**, below, is the whole of it, and it cannot run on your+ hostname.- **One identifier**, a UUID generated by the migration that created your database. It isattached to nothing else. `identify()` is never called, there are no person properties, and nouser, email or `ALLOWED_SIGN_IN` value is ever sent.@@ -177,6 +180,39 @@ our errors would carry contact fields.with parameters in it. Anything that does not match a strict path shape is sent as `other`, andso is any error class that is not a plain identifier.+## The landing page++`trycrm.ai` is the one place `posthog-js` runs: web analytics and session replay of strangers+reading a pitch. It is a website, not an install — there is no database behind that page and+no record within reach of it. Everything above still holds for the CRM itself.++**It cannot run on your hostname.** `analyticsAllowed` (`apps/app/lib/analytics.ts`) compares+`window.location.hostname` against two literals — `trycrm.ai` and `www.trycrm.ai` — and+`posthog-js` sits behind a dynamic `import()` on the far side of that check. Turn+`IS_MARKETING="true"` on and serve the same page from a domain of your own and the SDK is+never fetched: not sent and then dropped, never downloaded. The gate is the hostname rather+than `IS_MARKETING`, because `IS_MARKETING` is precisely the flag a self-hoster is invited to+set.++PostHog refuses it from the other side too. `recording_domains` on the receiving project names+the same two origins, so replay and heatmaps are declined for any other page that presents the+key.++**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.++**`anonymize_ips` stays on**, and that costs something here: PostHog drops the address before+geoip runs, so the landing page has no country, region or city. That setting is what makes the+no-IP promise above true for every install, and an install's anonymity outranks a marketing+map. A separate project is the only way to have both.++`ALLOWED_PROPERTIES` does not reach these events — it guards what `packages/telemetry` builds,+and these are the browser SDK's own. What it sends is ordinary web analytics: URL, referrer,+UTM parameters, browser, device, screen size, a session ID. Replay masks every input by+default and the page has no field to type in.+## What is never sent- Any `Contact` or `User` name, email, title or photo@@ -204,8 +240,11 @@ actually drops it. See `adrs/telemetry.md`.| `install` table | The UUID, the version, and when the last rollup went. One row, made by the migration || `telemetryMilestone` table | Which funnel steps have fired || `telemetryCounter` table | The one runtime number no other row records — `budget_exhausted` — drained by each rollup and put back if the send fails |+| `packages/telemetry/src/project.ts` | The key, the ingest host and the UI host. Three constants, no imports, so the browser can read them too || `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()` |Nothing is instrumented inside `apps/agent/agent/sandbox`, which runs `deny-all` egress bydesign. A capture in there would hang and then fail.diff --git a/packages/telemetry/package.json b/packages/telemetry/package.jsonindex 2a9718fc..149906cf 100644--- a/packages/telemetry/package.json+++ b/packages/telemetry/package.json@@ -6,7 +6,8 @@"exports": {".": "./src/index.ts","./allowlist": "./src/allowlist.ts",- "./install": "./src/install.ts"+ "./install": "./src/install.ts",+ "./project": "./src/project.ts"},"scripts": {"check-types": "tsc --noEmit",diff --git a/packages/telemetry/src/client.ts b/packages/telemetry/src/client.tsindex 634c476c..c9f7a014 100644--- a/packages/telemetry/src/client.ts+++ b/packages/telemetry/src/client.ts@@ -4,12 +4,9 @@ import { PostHog } from "posthog-node";import { type Properties, permitted } from "./allowlist";import { telemetryDisabled } from "./disabled";import { daysSince, readInstall } from "./install";+import { POSTHOG_HOST, POSTHOG_KEY } from "./project";import { commitSha } from "./version";-export const POSTHOG_KEY = "phc_xKYTYbcX9bEB7sEaCpfZUCqV7HBxZw3QQVztuXf86Q9N";--export const POSTHOG_HOST = "https://k.trycomp.ai";-const FLUSH_TIMEOUT_MS = 3_000;type Debug = (message: string) => void;diff --git a/packages/telemetry/src/index.ts b/packages/telemetry/src/index.tsindex 6238c169..3f412ba2 100644--- a/packages/telemetry/src/index.ts+++ b/packages/telemetry/src/index.ts@@ -25,8 +25,6 @@ export {captureNow,flushTelemetry,onTelemetryProblem,- POSTHOG_HOST,- POSTHOG_KEY,resetTelemetryClient,shutdownTelemetry,} from "./client";@@ -64,4 +62,5 @@ export {sameUtcDay,syncVersion,} from "./install";+export { POSTHOG_HOST, POSTHOG_KEY, POSTHOG_UI_HOST } from "./project";export { commitSha, crmVersion } from "./version";diff --git a/packages/telemetry/src/project.ts b/packages/telemetry/src/project.tsnew file mode 100644index 00000000..8f54553c--- /dev/null+++ b/packages/telemetry/src/project.ts@@ -0,0 +1,3 @@+export const POSTHOG_KEY = "phc_xKYTYbcX9bEB7sEaCpfZUCqV7HBxZw3QQVztuXf86Q9N";+export const POSTHOG_HOST = "https://k.trycomp.ai";+export const POSTHOG_UI_HOST = "https://us.posthog.com";diff --git a/packages/telemetry/test/client.integration.spec.ts b/packages/telemetry/test/client.integration.spec.tsindex 6a481fe1..8181a53e 100644--- a/packages/telemetry/test/client.integration.spec.ts+++ b/packages/telemetry/test/client.integration.spec.ts@@ -1,8 +1,9 @@import { afterEach, beforeEach, describe, expect, it } from "bun:test";import { db } from "@crm/db";-import { captureNow, POSTHOG_HOST, resetTelemetryClient } from "../src/client";+import { captureNow, resetTelemetryClient } from "../src/client";import { milestone } from "../src/events";import { forgetInstall, readInstall } from "../src/install";+import { POSTHOG_HOST } from "../src/project";const real = {fetch: globalThis.fetch,