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} )