add: 添加 Google Analytics

This commit is contained in:
hzm
2026-02-01 12:25:38 +08:00
parent 8af3445d2d
commit d77dfe6aa8

View File

@@ -1,3 +1,4 @@
import Script from 'next/script';
import './globals.css';
export const metadata = {
@@ -6,10 +7,25 @@ export const metadata = {
};
export default function RootLayout({ children }) {
const GA_ID = 'G-PD2JWJHVEM'; // 请在此处替换您的 Google Analytics ID
return (
<html lang="zh-CN">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
{/* Google Analytics */}
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_ID}');
`}
</Script>
</head>
<body>
{children}