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..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. @@ -18,6 +20,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: stripIngestPrefix, + }, + "/ingest/array": { + target: "https://us-assets.i.posthog.com", + changeOrigin: true, + rewrite: stripIngestPrefix, + }, + "/ingest": { + target: "https://us.i.posthog.com", + changeOrigin: true, + rewrite: stripIngestPrefix, + }, + }, }, resolve: { dedupe: [