Conversation
📝 WalkthroughWalkthroughConditionally injects the Microsoft Clarity analytics script into the RootLayout when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/app/layout.tsx (1)
94-94: Move the hardcoded Clarity project ID to an environment variable.The existing
GA_IDis already read fromprocess.env.NEXT_PUBLIC_GA_ID— apply the same pattern here so the Clarity project ID can be rotated or changed without a code change.♻️ Proposed refactor
Add to your
.envfiles:NEXT_PUBLIC_CLARITY_ID=vmrhru1kztThen apply this diff:
const GA_ID = process.env.NEXT_PUBLIC_GA_ID; +const CLARITY_ID = process.env.NEXT_PUBLIC_CLARITY_ID; const isProd = process.env.NEXT_PUBLIC_APP_ENV === "production";And update the condition and inline script:
- {isProd && ( + {isProd && CLARITY_ID && ( <Script id="microsoft-clarity" strategy="afterInteractive"> {` (function(c,l,a,r,i,t,y){ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); - })(window, document, "clarity", "script", "vmrhru1kzt"); + })(window, document, "clarity", "script", "${CLARITY_ID}"); `} </Script> )}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app/layout.tsx` at line 94, Replace the hardcoded Clarity project ID string ("vmrhru1kzt") in src/app/layout.tsx with an environment variable similar to GA_ID: read NEXT_PUBLIC_CLARITY_ID from process.env and use that value when injecting the Clarity script (the IIFE that calls clarity/script with arguments including "vmrhru1kzt"); also update any conditional that checks for GA_ID to also check NEXT_PUBLIC_CLARITY_ID before injecting, and ensure you fall back or skip injection if NEXT_PUBLIC_CLARITY_ID is undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/app/layout.tsx`:
- Around line 86-98: Remove the explicit <head> wrapper around the Script in
layout.tsx: instead of rendering <head>{isProd && <Script ...>}</head>, place
the next/script <Script> component directly in the JSX tree (e.g., alongside
where GoogleAnalytics is rendered) and guard it with the isProd check; this
prevents emitting an empty <head> when not in production and avoids hydration
warnings—also prefer the metadata API for any actual <head> metadata rather than
manual head markup.
---
Nitpick comments:
In `@src/app/layout.tsx`:
- Line 94: Replace the hardcoded Clarity project ID string ("vmrhru1kzt") in
src/app/layout.tsx with an environment variable similar to GA_ID: read
NEXT_PUBLIC_CLARITY_ID from process.env and use that value when injecting the
Clarity script (the IIFE that calls clarity/script with arguments including
"vmrhru1kzt"); also update any conditional that checks for GA_ID to also check
NEXT_PUBLIC_CLARITY_ID before injecting, and ensure you fall back or skip
injection if NEXT_PUBLIC_CLARITY_ID is undefined.
⚡️ Lighthouse Report🏠 URL: http://localhost:3000/
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/app/layout.tsx (1)
93-100: Move the Clarity project ID to env config.Hardcoding the ID on Line 99 makes rotation and environment separation harder. Prefer
NEXT_PUBLIC_CLARITY_PROJECT_IDand only render when it is set.♻️ Proposed refactor
const GA_ID = process.env.NEXT_PUBLIC_GA_ID; const isProd = process.env.NEXT_PUBLIC_APP_ENV === "production"; +const CLARITY_PROJECT_ID = process.env.NEXT_PUBLIC_CLARITY_PROJECT_ID; @@ - {isProd && ( + {isProd && CLARITY_PROJECT_ID && ( <Script id="microsoft-clarity" strategy="afterInteractive"> {` (function(c,l,a,r,i,t,y){ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); - })(window, document, "clarity", "script", "vmrhru1kzt"); + })(window, document, "clarity", "script", "${CLARITY_PROJECT_ID}"); `} </Script> )}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app/layout.tsx` around lines 93 - 100, Replace the hardcoded Clarity project ID in the microsoft-clarity Script block with the environment variable NEXT_PUBLIC_CLARITY_PROJECT_ID and only render the <Script id="microsoft-clarity" ...> when that env var is present; locate the Script block in src/app/layout.tsx (Script id="microsoft-clarity") and change logic to read process.env.NEXT_PUBLIC_CLARITY_PROJECT_ID (or use Next.js runtime env access) and guard rendering so the injected script template uses that variable instead of "vmrhru1kzt".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/app/layout.tsx`:
- Around line 92-102: Wrap all analytics script injections (the Script with id
"microsoft-clarity" and any Vercel Analytics, SpeedInsights, GoogleAnalytics
injections) behind a runtime consent check instead of only isProd; add or use a
consent API (e.g., hasConsent('analytics') or read consent cookie/state) inside
the Layout component and only render or dynamically inject those Script
components when consent is true, or queue them and load them in a
useEffect/dynamic import after consent is granted; ensure the check is applied
to the Script id="microsoft-clarity" and corresponding places that render
analytics so no tracking code is executed before user consent.
---
Nitpick comments:
In `@src/app/layout.tsx`:
- Around line 93-100: Replace the hardcoded Clarity project ID in the
microsoft-clarity Script block with the environment variable
NEXT_PUBLIC_CLARITY_PROJECT_ID and only render the <Script
id="microsoft-clarity" ...> when that env var is present; locate the Script
block in src/app/layout.tsx (Script id="microsoft-clarity") and change logic to
read process.env.NEXT_PUBLIC_CLARITY_PROJECT_ID (or use Next.js runtime env
access) and guard rendering so the injected script template uses that variable
instead of "vmrhru1kzt".
⚡️ Lighthouse Report🏠 URL: http://localhost:3000/
|
🔗 관련 이슈
✨ 작업 단계 및 변경 사항
🧪 테스트 방법
리뷰어가 확인해야 할 핵심 포인트를 적어주세요.
📸 스크린샷 (선택)
✅ 체크리스트
Phase에 맞는 이슈 체크리스트를 모두 완료했는가?Summary by CodeRabbit