add GoogleAnalytics

This commit is contained in:
tianyaxiang 2025-02-04 10:03:26 +08:00
parent bb60f67316
commit 9e1e70a1b6
2 changed files with 24 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import 'katex/dist/katex.min.css'
import { ThemeProvider } from '@/components/theme/ThemeProvider'
import { cn } from '@/lib/utils'
import { Toaster } from '@/components/ui/toaster'
import { GoogleAnalytics } from '@/components/GoogleAnalytics'
const inter = Inter({ subsets: ['latin'] })
@ -46,6 +47,7 @@ export default function RootLayout({
'min-h-screen bg-background font-sans antialiased',
inter.className
)}>
<GoogleAnalytics />
<ThemeProvider
attribute="class"
defaultTheme="system"

View File

@ -0,0 +1,22 @@
'use client'
import Script from 'next/script'
export function GoogleAnalytics() {
return (
<>
<Script
src="https://www.googletagmanager.com/gtag/js?id=G-Y51DW9V3F6"
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-Y51DW9V3F6');
`}
</Script>
</>
)
}