From 4e30ddefc5c242e1f9bd3390089e894b342e6310 Mon Sep 17 00:00:00 2001 From: mzaxd Date: Tue, 24 Feb 2026 08:45:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Vercel=20=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=87=BD=E6=95=B0=E4=BC=A0=E9=80=92=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=A2=84=E6=B8=B2=E6=9F=93=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/VercelMetrics.tsx | 24 ++++++++++++++++++++++++ src/app/layout.tsx | 24 ++---------------------- 2 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 src/app/VercelMetrics.tsx diff --git a/src/app/VercelMetrics.tsx b/src/app/VercelMetrics.tsx new file mode 100644 index 0000000..c3e68e9 --- /dev/null +++ b/src/app/VercelMetrics.tsx @@ -0,0 +1,24 @@ +"use client" + +import { Analytics } from "@vercel/analytics/next" +import { SpeedInsights } from "@vercel/speed-insights/next" + +const isTrackablePath = (url: string): boolean => { + try { + const pathname = new URL(url).pathname + + // Only keep user-facing locale pages to control usage on the Hobby plan. + return pathname === "/zh" || pathname === "/en" || pathname.startsWith("/zh/") || pathname.startsWith("/en/") + } catch { + return false + } +} + +export function VercelMetrics() { + return ( + <> + (isTrackablePath(event.url) ? event : null)} /> + (isTrackablePath(data.url) ? data : null)} /> + + ) +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 51f1f2b..d8d00dd 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,5 @@ import type { Metadata } from "next" -import { Analytics } from "@vercel/analytics/next" -import { SpeedInsights } from "@vercel/speed-insights/next" +import { VercelMetrics } from "./VercelMetrics" import "./globals.css" export const metadata: Metadata = { @@ -10,17 +9,6 @@ export const metadata: Metadata = { const isVercelProduction = process.env.VERCEL_ENV === "production" -const isTrackablePath = (url: string): boolean => { - try { - const pathname = new URL(url).pathname - - // Only keep user-facing locale pages to control usage on the Hobby plan. - return pathname === "/zh" || pathname === "/en" || pathname.startsWith("/zh/") || pathname.startsWith("/en/") - } catch { - return false - } -} - export default function RootLayout({ children, }: Readonly<{ @@ -30,15 +18,7 @@ export default function RootLayout({ {children} - {isVercelProduction ? ( - <> - (isTrackablePath(event.url) ? event : null)} /> - (isTrackablePath(data.url) ? data : null)} - /> - - ) : null} + {isVercelProduction ? : null} )