From 3005f289e53da5da4f24f598a98e65afce1e8d62 Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:27:20 +0000 Subject: [PATCH 1/2] feat(analytics): proxy posthog-js capture through /ingest Add same-origin Vercel rewrites from /ingest to the PostHog US ingest and asset hosts. Set api_host to /ingest and ui_host to the PostHog app. Add a matching Vite dev-server proxy so that local capture continues to work. Co-Authored-By: Claude Opus 5.5 Generated-By: PostHog Desktop Task-Id: 6ec7c1b0-ee13-449c-a6a4-17f92ad9c46b --- src/hooks.client.ts | 3 ++- vercel.json | 14 ++++++++++++++ vite.config.ts | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/hooks.client.ts b/src/hooks.client.ts index d713138..b6a625b 100644 --- a/src/hooks.client.ts +++ b/src/hooks.client.ts @@ -10,7 +10,7 @@ export function isPostHogInitialized() { export function init() { const key = "phc_AS2JXQsqEwNNreH5kra5Eefd5TijExE5eiLfwdzXLhPg"; - const host = "https://us.i.posthog.com"; + const host = "/ingest"; if (!key || !host) { if (dev) { @@ -23,6 +23,7 @@ export function init() { posthog.init(key, { api_host: host, + ui_host: "https://us.posthog.com", defaults: "2026-08-30", capture_pageview: "history_change", capture_exceptions: { diff --git a/vercel.json b/vercel.json index 4c81f26..02e0965 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,20 @@ { "$schema": "https://openapi.vercel.sh/vercel.json", "framework": "sveltekit", + "rewrites": [ + { + "source": "/ingest/static/:path*", + "destination": "https://us-assets.i.posthog.com/static/:path*" + }, + { + "source": "/ingest/array/:path*", + "destination": "https://us-assets.i.posthog.com/array/:path*" + }, + { + "source": "/ingest/:path*", + "destination": "https://us.i.posthog.com/:path*" + } + ], "redirects": [ { "source": "/docs/2026-09-18-why-lightcms", diff --git a/vite.config.ts b/vite.config.ts index 92f6336..1b49670 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,6 +18,24 @@ export default defineConfig({ }, server: { allowedHosts: true, + // Mirrors the PostHog rewrites in vercel.json so `api_host: "/ingest"` works in dev. + proxy: { + "/ingest/static": { + target: "https://us-assets.i.posthog.com", + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ""), + }, + "/ingest/array": { + target: "https://us-assets.i.posthog.com", + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ""), + }, + "/ingest": { + target: "https://us.i.posthog.com", + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ingest/, ""), + }, + }, }, resolve: { dedupe: [ From 09b42b252b1355ffd79029ada44978ca41ce51c8 Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:27:50 +0000 Subject: [PATCH 2/2] refactor(dev): share the /ingest prefix rewrite in the dev proxy Co-Authored-By: Claude Opus 5.5 Generated-By: PostHog Desktop Task-Id: 6ec7c1b0-ee13-449c-a6a4-17f92ad9c46b --- vite.config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 1b49670..9596fe7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,6 +4,8 @@ import tailwindcss from "@tailwindcss/vite"; import { mdsvex } from "mdsvex"; import { defineConfig } from "vite-plus"; +const stripIngestPrefix = (path: string) => path.replace(/^\/ingest/, ""); + export default defineConfig({ test: { // Vitest v4 compatibility: preserve mock call history. @@ -23,17 +25,17 @@ export default defineConfig({ "/ingest/static": { target: "https://us-assets.i.posthog.com", changeOrigin: true, - rewrite: (path) => path.replace(/^\/ingest/, ""), + rewrite: stripIngestPrefix, }, "/ingest/array": { target: "https://us-assets.i.posthog.com", changeOrigin: true, - rewrite: (path) => path.replace(/^\/ingest/, ""), + rewrite: stripIngestPrefix, }, "/ingest": { target: "https://us.i.posthog.com", changeOrigin: true, - rewrite: (path) => path.replace(/^\/ingest/, ""), + rewrite: stripIngestPrefix, }, }, },