diff --git a/src/app/layout.tsx b/src/app/layout.tsx index ab09fa8..d89639b 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -2,6 +2,7 @@ import type { Metadata } from 'next'; import { Geist, Geist_Mono } from 'next/font/google'; import '@/styles/globals.css'; import ClientHeader from '@/components/ClientHeader'; +import GoogleAnalytics from '@/components/GoogleAnalytics'; const geistSans = Geist({ variable: '--font-geist-sans', @@ -25,9 +26,20 @@ export default function RootLayout({ }>) { return ( + + {/* 구글 애드센스 스크립트 */} + + + {/* 구글 애널리틱스 컴포넌트 */} + + {/* 전역 헤더 */} diff --git a/src/components/GoogleAnalytics.tsx b/src/components/GoogleAnalytics.tsx new file mode 100644 index 0000000..308c60f --- /dev/null +++ b/src/components/GoogleAnalytics.tsx @@ -0,0 +1,37 @@ +'use client'; // 클라이언트 컴포넌트임을 명시합니다. + +import Script from 'next/script'; + +const GoogleAnalytics = () => { + const gaId = process.env.NEXT_PUBLIC_GA_ID; + + // 환경 변수가 설정되지 않았다면 아무것도 렌더링하지 않습니다. + if (!gaId) { + return null; + } + + return ( + <> + {/* 외부 gtag.js 스크립트를 로드합니다. */} +