프론트엔드/Next.js
[Next.js] Next.js 15버전 GA 태그 추가 방법
순코딩
2025. 1. 6. 17:49
설치
npm install @next/third-parties@latest
코드 (전역 경로 GA)
app / layout.tsx
import { GoogleAnalytics } from '@next/third-parties/google'
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
<GoogleAnalytics gaId="G-XYZ" />
</html>
)
}
코드 (단일 경로 GA)
app / page.tsx
import { GoogleAnalytics } from '@next/third-parties/google'
export default function Page() {
return <GoogleAnalytics gaId="G-XYZ" />
}