From 0b9ddeedc8f2fc367eb4b98b247836089a4496a3 Mon Sep 17 00:00:00 2001 From: Unchained Date: Wed, 1 Apr 2026 07:42:34 +0200 Subject: [PATCH] fix(analytics): properly forward client IPs to Rybbit and OpenPanel - Create new API route /api/rybbit/track to proxy Rybbit tracking requests - Extract real client IP from Cloudflare headers (cf-connecting-ip) - Forward X-Forwarded-For and X-Real-IP headers to analytics backends - Update OpenPanel proxy to also forward client IP - Update next.config.ts rewrite to use internal API route This fixes geo-location issues where all traffic appeared to come from Cloudflare edge locations instead of actual visitor countries. --- next.config.ts | 6 - src/app/[locale]/layout.tsx | 2 +- src/app/api/op/track/route.ts | 76 ------ src/app/api/op1/route.ts | 24 -- src/app/api/rybbit/track/route.ts | 60 +++-- src/components/product/ProductCard.tsx | 1 + .../providers/AnalyticsProvider.tsx | 21 +- src/lib/analytics.ts | 231 ++++-------------- src/lib/analytics/providers/RybbitProvider.ts | 84 ++++++- src/middleware.ts | 2 +- 10 files changed, 169 insertions(+), 338 deletions(-) delete mode 100644 src/app/api/op/track/route.ts delete mode 100644 src/app/api/op1/route.ts diff --git a/next.config.ts b/next.config.ts index e50d98b..19fb2fa 100644 --- a/next.config.ts +++ b/next.config.ts @@ -7,8 +7,6 @@ const nextConfig: NextConfig = { output: 'standalone', async rewrites() { const rybbitHost = process.env.NEXT_PUBLIC_RYBBIT_HOST || "https://rybbit.nodecrew.me"; - const openpanelUrl = process.env.OPENPANEL_API_URL || "https://op.nodecrew.me/api"; - const openpanelScriptUrl = "https://op.nodecrew.me"; return [ { source: "/api/script.js", @@ -30,10 +28,6 @@ const nextConfig: NextConfig = { source: "/api/session-replay/record/:id", destination: `${rybbitHost}/api/session-replay/record/:id`, }, - { - source: "/api/op/track", - destination: `${openpanelUrl}/track`, - }, ]; }, images: { diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx index a80fb97..aa345bd 100644 --- a/src/app/[locale]/layout.tsx +++ b/src/app/[locale]/layout.tsx @@ -53,7 +53,7 @@ export default async function LocaleLayout({