설치
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" />
}
'프론트엔드 > Next.js' 카테고리의 다른 글
[Next.js] Next.js 구글 검색 엔진 최적화(SEO) 가이드 (0) | 2025.01.08 |
---|---|
[Next.js] Next.js 네이버 웹마스터 검색 엔진 최적화(SEO) 가이드 (0) | 2025.01.08 |
[Next.js] Next.js 15버전 PWA 적용 방법 (0) | 2025.01.06 |
[Next.js] 이미지 최적화, <Image/> 사용 방법 (0) | 2025.01.04 |
[Next.js] Next.js + styled-components + MUI 프로젝트 세팅(그리고 styled-components 글로벌 스타일링과 MUI 커스텀 테마 적용하기) (0) | 2024.12.19 |