gridly icon indicating copy to clipboard operation
gridly copied to clipboard

Add Vercel Analytics script to root layout

Open AdityaKodez opened this issue 9 months ago โ€ข 5 comments

Motivation

  • Initialize Vercel Insights analytics site-wide by loading the Insights script in the root app layout so page metrics are collected across the application.

Description

  • Imported Script from next/script and added <Script src="/_vercel/insights/script.js" strategy="afterInteractive" /> to app/layout.tsx so the insights script is injected after the app becomes interactive.

Testing

  • Ran npm run lint which completed successfully.
  • Attempted npm i @vercel/analytics to add the optional package, but the install was blocked by the environment registry with a 403 Forbidden error.

Codex Task

Summary by CodeRabbit

  • Chores
    • Enhanced application monitoring to better track performance metrics and user interactions across the platform.

AdityaKodez avatar Feb 21 '26 17:02 AdityaKodez

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gridly Ready Ready Preview, Comment Feb 21, 2026 5:38pm

vercel[bot] avatar Feb 21 '26 17:02 vercel[bot]

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Summary by Beetle

This PR integrates Vercel Analytics into the application by adding the Vercel Insights tracking script to the root layout. This enables automatic collection of web vitals and user analytics data for monitoring application performance and user behavior in production environments.

๐Ÿ“ File Changes Summary (Consolidated across all commits):

File Status Changes Description
app/layout.tsx Modified +2/-0 Added Vercel Analytics integration by importing Next.js Script component and injecting the Vercel Insights script with afterInteractive loading strategy to track web vitals and analytics without blocking page rendering

Total Changes: 1 file changed, +2 additions, -0 deletions

๐ŸŽฏ Key Changes:

  • Analytics Integration: Added Vercel Analytics tracking script (/_vercel/insights/script.js) to the root layout component
  • Performance-Conscious Loading: Used afterInteractive strategy to ensure the analytics script loads after the page becomes interactive, preventing any impact on initial page load performance
  • Minimal Implementation: Clean, non-invasive integration requiring only 2 lines of code (import statement and Script component)
  • Application-Wide Coverage: Placed in the root layout ensures analytics tracking across all pages and routes in the application

๐Ÿ“Š Impact Assessment:

  • Security: โœ… Low Risk - The script is loaded from Vercel's official CDN path (/_vercel/insights/script.js), which is a trusted first-party resource. No external third-party domains or sensitive data exposure. The script runs in the browser context with standard web permissions.
  • Performance: โœ… Minimal Impact - The afterInteractive loading strategy ensures the analytics script loads only after the page becomes interactive, preventing any blocking of critical rendering path. This is the recommended approach for analytics scripts. Expected overhead is negligible (<50ms) and occurs after user interaction is already possible.
  • Maintainability: โœ… Excellent - The implementation is clean, follows Next.js best practices, and uses the official Script component with proper strategy configuration. The change is well-isolated in the root layout, making it easy to modify or remove if needed. No additional dependencies or configuration files required.
  • Testing: โš ๏ธ Manual Verification Recommended - While the code change is straightforward, it's recommended to verify in a Vercel deployment environment that:
  • Analytics data is being collected correctly
  • No console errors appear related to the script
  • Page load performance metrics remain within acceptable ranges
  • The script doesn't interfere with existing functionality
โš™๏ธ Settings

Severity Threshold: Medium โ€” Balanced feedback โ€” medium and high severity issues only. โ€” Change in Settings Custom Rules: Define your own review rules โ€” Set Custom Rules PR Summary: Configure PR summary โ€” Change in Settings

๐Ÿ“– User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle ยท X ยท LinkedIn

beetle-ai[bot] avatar Feb 21 '26 17:02 beetle-ai[bot]

๐Ÿ“ Walkthrough

Walkthrough

This change adds dynamic loading of Vercel Insights script to the application root layout. The Script component from Next.js is imported and configured to load the insights tracking script with an "afterInteractive" strategy, enabling application performance monitoring.

Changes

Cohort / File(s) Summary
Vercel Insights Integration
app/layout.tsx
Added import of Script component from next/script and rendered a Script tag loading Vercel Insights script with afterInteractive strategy for performance monitoring.

Estimated code review effort

๐ŸŽฏ 1 (Trivial) | โฑ๏ธ ~2 minutes

Poem

๐Ÿฐ A script so light, now takes its flight,
Performance insights, shining bright,
Analytics dance in the browser's delight,
With afterInteractive, all feels right! โœจ


[!NOTE]

๐ŸŽ Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Feb 21 '26 17:02 coderabbitai[bot]

โœ… You're good to merge this PR! No issues found. Great job!

Settings
โš™๏ธ Settings

Severity Threshold: Medium โ€” Balanced feedback โ€” medium and high severity issues only. โ€” Change in Settings Custom Rules: Define your own review rules โ€” Set Custom Rules PR Summary: Configure PR summary โ€” Change in Settings

๐Ÿ“– User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

beetle-ai[bot] avatar Feb 21 '26 17:02 beetle-ai[bot]