A desktop coding agent with free access to frontier models.
TypeScript
fix: no analytics without our own key
ogsamratc3314563fddb
diff --git a/apps/app/src/app/lib/analytics-key.ts b/apps/app/src/app/lib/analytics-key.tsindex f685c198..c6726720 100644--- a/apps/app/src/app/lib/analytics-key.ts+++ b/apps/app/src/app/lib/analytics-key.ts@@ -1,11 +1,8 @@-export const DEFAULT_POSTHOG_KEY = "phc_4YnPTlDVYPjgwKvLuNxhbHjV5kadgvd7XLzVHWnCXAI";-/*** Resolve the PostHog project key. `raw` is VITE_OMNIRUSH_POSTHOG_KEY.- * Unset uses the default key in prod builds and stays silent in dev builds.- * Explicit strings are used after trim; an empty string disables analytics in any build.+ * There is no built-in key: analytics stay off unless a build sets one.+ * Explicit strings are used after trim; unset or blank disables analytics.*/-export function resolvePosthogKey(raw: unknown, isDev: boolean): string {- if (typeof raw === "string") return raw.trim(); // explicit value wins; "" disables- return isDev ? "" : DEFAULT_POSTHOG_KEY;+export function resolvePosthogKey(raw: unknown): string {+ return typeof raw === "string" ? raw.trim() : "";}diff --git a/apps/app/src/app/lib/analytics.ts b/apps/app/src/app/lib/analytics.tsindex 7b5702ce..6fd8b826 100644--- a/apps/app/src/app/lib/analytics.ts+++ b/apps/app/src/app/lib/analytics.ts@@ -8,8 +8,8 @@* into an explicit survey field (e.g. the onboarding attribution survey).* - Fire-and-forget: analytics must never break or slow the app.* - Respect the user: a single `analyticsEnabled` preference (Settings ->- * Preferences) turns everything off; an explicitly blank PostHog key means- * no network.+ * Preferences) turns everything off; without a build-time PostHog key+ * nothing is sent over the network.* - Every capture is mirrored into the local app inspector* (`window.__omnirush.record("analytics.<event>")`) so coded evals can* assert instrumentation without any analytics backend.@@ -23,10 +23,10 @@ const ENV_APP_VERSION = String(import.meta.env.VITE_OMNIRUSH_APP_VERSION ?? "").const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";-// Packaged releases use the default publishable key; dev builds stay silent-// unless VITE_OMNIRUSH_POSTHOG_KEY is set. Set it to "" to disable analytics-// in any build. The inspector mirror still records events locally either way.-const POSTHOG_KEY = resolvePosthogKey(import.meta.env.VITE_OMNIRUSH_POSTHOG_KEY, import.meta.env.DEV);+// No built-in key: nothing is sent unless the build sets+// VITE_OMNIRUSH_POSTHOG_KEY. The inspector mirror still records events+// locally either way.+const POSTHOG_KEY = resolvePosthogKey(import.meta.env.VITE_OMNIRUSH_POSTHOG_KEY);const POSTHOG_HOST = (ENV_POSTHOG_HOST || DEFAULT_POSTHOG_HOST).replace(/\/+$/, "");const PREFS_STORAGE_KEY = "omnirush.preferences";diff --git a/apps/app/src/react-app/kernel/local-provider.tsx b/apps/app/src/react-app/kernel/local-provider.tsxindex d6dc54e7..94eda9b7 100644--- a/apps/app/src/react-app/kernel/local-provider.tsx+++ b/apps/app/src/react-app/kernel/local-provider.tsx@@ -59,8 +59,8 @@ export type LocalPreferences = {*/hasCompletedOnboarding: boolean;/**- * Anonymous product analytics (PostHog). On by default with a visible- * opt-out in Settings -> Preferences. Never includes message content.+ * Anonymous product analytics (PostHog). Only sent when the build sets a+ * PostHog key; opt-out in Settings -> Preferences. Never includes message content.*/analyticsEnabled: boolean;/**diff --git a/apps/app/tests/analytics-key.test.ts b/apps/app/tests/analytics-key.test.tsindex e5d34e13..b6ca452b 100644--- a/apps/app/tests/analytics-key.test.ts+++ b/apps/app/tests/analytics-key.test.ts@@ -1,29 +1,27 @@import { describe, expect, test } from "bun:test";-import { DEFAULT_POSTHOG_KEY, resolvePosthogKey } from "../src/app/lib/analytics-key";+import * as analyticsKey from "../src/app/lib/analytics-key";+import { resolvePosthogKey } from "../src/app/lib/analytics-key";describe("analytics-key", () => {- test("uses the default key for packaged release builds without an env override", () => {- expect(resolvePosthogKey(undefined, false)).toBe(DEFAULT_POSTHOG_KEY);+ test("ships without a built-in key", () => {+ expect(Object.keys(analyticsKey)).toEqual(["resolvePosthogKey"]);});- test("stays silent for dev builds without an env override", () => {- expect(resolvePosthogKey(undefined, true)).toBe("");+ test("stays silent without an env key", () => {+ expect(resolvePosthogKey(undefined)).toBe("");+ expect(resolvePosthogKey(null)).toBe("");});- test("treats an explicit blank as disabled in prod builds", () => {- expect(resolvePosthogKey("", false)).toBe("");+ test("treats an explicit blank as disabled", () => {+ expect(resolvePosthogKey("")).toBe("");});test("trims whitespace to disabled", () => {- expect(resolvePosthogKey(" ", true)).toBe("");+ expect(resolvePosthogKey(" ")).toBe("");});- test("uses an explicit key in dev builds", () => {- expect(resolvePosthogKey("phc_custom", true)).toBe("phc_custom");- });-- test("uses an explicit key in prod builds", () => {- expect(resolvePosthogKey("phc_custom", false)).toBe("phc_custom");+ test("uses an explicit key after trim", () => {+ expect(resolvePosthogKey(" phc_custom ")).toBe("phc_custom");});});diff --git a/docs/enterprise/outbound-access.json b/docs/enterprise/outbound-access.jsonindex 371233ef..afc910f4 100644--- a/docs/enterprise/outbound-access.json+++ b/docs/enterprise/outbound-access.json@@ -274,7 +274,7 @@"host": "us.i.posthog.com","kind": "fetched","components": ["renderer"],- "purpose": "Optional product analytics endpoint when analytics are enabled and a PostHog key is configured.",+ "purpose": "Optional product analytics endpoint, used only when a build sets VITE_OMNIRUSH_POSTHOG_KEY and analytics are enabled. Release builds set no key.","requirement": "optional","blockedEffect": "Analytics events are dropped silently; user-facing app behavior is unaffected.","override": "VITE_OMNIRUSH_POSTHOG_HOST; users can disable analytics with the analyticsEnabled preference"diff --git a/ee/apps/landing/app/layout.tsx b/ee/apps/landing/app/layout.tsxindex d7273d80..514bd34b 100644--- a/ee/apps/landing/app/layout.tsx+++ b/ee/apps/landing/app/layout.tsx@@ -11,7 +11,7 @@ import { DownloadProvider } from "../components/download-link";// Matches the server-side gate in lib/posthog-server.ts.// Local pnpm dev, local prod builds, and Vercel previews load no PostHog at all (no autocapture/pageviews), so only real production traffic reaches analytics.// VERCEL_ENV is baked at build time for static pages, which is correct on Vercel production builds.-const posthogEnabled = process.env.VERCEL_ENV === "production";+const posthogEnabled = process.env.VERCEL_ENV === "production" && POSTHOG_PROJECT_KEY !== "";const organizationSchema = {"@context": "https://schema.org",diff --git a/ee/apps/landing/lib/posthog-client.ts b/ee/apps/landing/lib/posthog-client.tsindex cecc65c0..dc53b01a 100644--- a/ee/apps/landing/lib/posthog-client.ts+++ b/ee/apps/landing/lib/posthog-client.ts@@ -8,7 +8,8 @@ declare global {}}-export const POSTHOG_PROJECT_KEY = "phc_4YnPTlDVYPjgwKvLuNxhbHjV5kadgvd7XLzVHWnCXAI";+// No built-in key: PostHog stays off unless the build sets LANDING_POSTHOG_KEY.+export const POSTHOG_PROJECT_KEY = (process.env.LANDING_POSTHOG_KEY ?? "").trim();export function capturePosthogEvent(event: string, properties?: Record<string, unknown>): void {if (typeof window === "undefined") {diff --git a/ee/apps/landing/lib/posthog-server.ts b/ee/apps/landing/lib/posthog-server.tsindex 00e9adb7..6d71a956 100644--- a/ee/apps/landing/lib/posthog-server.ts+++ b/ee/apps/landing/lib/posthog-server.ts@@ -3,6 +3,9 @@ import { POSTHOG_PROJECT_KEY } from "./posthog-client";const POSTHOG_SERVER_TIMEOUT_MS = 400;export async function capturePosthogServerEvent(event: string, properties: Record<string, unknown>): Promise<void> {+ if (!POSTHOG_PROJECT_KEY) {+ return;+ }if (process.env.VERCEL_ENV !== "production" && !process.env.LANDING_POSTHOG_HOST) {return;}diff --git a/ee/apps/landing/next.config.js b/ee/apps/landing/next.config.jsindex 027e3df1..897d47fb 100644--- a/ee/apps/landing/next.config.js+++ b/ee/apps/landing/next.config.js@@ -13,6 +13,7 @@ const nextConfig = {// matches the runtime env, and local `next start` mirrors what was built.env: {VERCEL_ENV: process.env.VERCEL_ENV || "",+ LANDING_POSTHOG_KEY: process.env.LANDING_POSTHOG_KEY || "",},async rewrites() {return [diff --git a/packages/docs/start-here/outbound-network-access.mdx b/packages/docs/start-here/outbound-network-access.mdxindex ce287a0f..31a1c514 100644--- a/packages/docs/start-here/outbound-network-access.mdx+++ b/packages/docs/start-here/outbound-network-access.mdx@@ -38,7 +38,7 @@ Common misses:| Your model catalog mirror, if configured | Optional | Model catalog passed to the engine as `OPENCODE_MODELS_URL`. There is no default catalog. | The engine keeps the model list bundled with it. || `cdn.simpleicons.org` | Optional | Provider icons when no local icon exists. | Some icons are missing. || `www.google.com` | Optional | Favicon image service and embedded browser new-tab page. | Favicons or the browser panel new tab may not load. |-| `us.i.posthog.com` | Optional | Product analytics when analytics are enabled. | Analytics are dropped silently. |+| `us.i.posthog.com` | Optional | Product analytics, only when a build sets `VITE_OMNIRUSH_POSTHOG_KEY` (release builds set none). | Analytics are dropped silently. || `discord.gg`, `ollama.com`, `opencode.ai`, `linear.app`, `mail.google.com` | Optional or link-only | Docs, feedback, community, provider help, local model links, sample links, and generated Gmail links. | Links do not open; core app behavior is unaffected. |`code.claude.com` and `schemas.agentskills.io` appear in source or schema metadata. They are findable in the manifest, but OmniRush.ai does not fetch them for normal runtime behavior.