Skip to content

Commit 87a6ded

Browse files
youngminssclaudeRookieAND
authored
feat: GTM(Google Tag Manager) 통합을 위한 Analytics 컴포넌트 추가 (#57)
* feat: GTM(Google Tag Manager) 통합을 위한 Analytics 컴포넌트 추가 @next/third-parties 라이브러리를 사용하여 GTM을 통합하고, Clarity/Hotjar는 GTM 콘솔에서 관리하는 방식으로 구현 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci: gtm id 를 nextjs 환경 변수에 추가 * refactor: 개발 환경에서 GTM ID 미설정 시 경고 메시지 추가 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: RookieAND <gwangin1999@naver.com>
1 parent 7bc3e12 commit 87a6ded

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

.github/workflows/production-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
run: |
4646
echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" > .env.production
4747
echo "NEXT_PUBLIC_AWS_S3=${{ secrets.NEXT_PUBLIC_AWS_S3 }}" >> .env.production
48+
echo "NEXT_PUBLIC_GTM_ID=${{ secrets.NEXT_PUBLIC_GTM_ID }}" >> .env.production
4849
4950
- name: Build and Push Client image
5051
if: steps.changes.outputs.client == 'true'

app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Metadata, Viewport } from "next";
22
import { Geist, Geist_Mono } from "next/font/google";
3+
import { Analytics } from "#/components/analytics";
34
import "./globals.css";
45

56
const geistSans = Geist({
@@ -47,6 +48,7 @@ export default function RootLayout({
4748
className={`${geistSans.variable} ${geistMono.variable} antialiased ygi:overflow-x-hidden`}
4849
>
4950
{children}
51+
<Analytics />
5052
</body>
5153
</html>
5254
);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"@hookform/resolvers": "^5.2.2",
1515
"@lottiefiles/react-lottie-player": "^3.6.0",
16+
"@next/third-parties": "^16.1.6",
1617
"@radix-ui/react-slot": "^1.2.4",
1718
"@tanstack/react-query": "^5.90.16",
1819
"class-variance-authority": "^0.7.1",

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client";
2+
3+
import { GoogleTagManager } from "@next/third-parties/google";
4+
5+
const GTM_ID = process.env.NEXT_PUBLIC_GTM_ID;
6+
7+
export const Analytics = () => {
8+
if (!GTM_ID) {
9+
if (process.env.NODE_ENV === "development") {
10+
console.warn(
11+
"Google Tag Manager ID(NEXT_PUBLIC_GTM_ID) is not configured.",
12+
);
13+
}
14+
return null;
15+
}
16+
17+
return <GoogleTagManager gtmId={GTM_ID} />;
18+
};

src/components/analytics/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Analytics } from "./Analytics";

0 commit comments

Comments
 (0)