Skip to content

Commit 1e9ed91

Browse files
committed
Add Vercel Web Analytics to Next.js
## Vercel Web Analytics Implementation ### Summary Successfully installed and configured Vercel Web Analytics for the CodeStorm Hub Next.js project using the App Router architecture. ### Changes Made #### 1. Package Installation - Installed `@vercel/analytics` package using npm - Updated `package.json` with the new dependency - Updated `package-lock.json` with resolved dependency tree #### 2. Code Changes - **Modified: `/src/app/layout.tsx`** - Added import statement: `import { Analytics } from "@vercel/analytics/next";` - Added `<Analytics />` component inside the `<body>` tag, after the `<ThemeProvider>` wrapper - Placement follows best practices for App Router projects, ensuring the component is rendered on every page ### Implementation Details The project uses the **App Router** architecture (files located in `/src/app/`), so the Analytics component was: - Imported from the correct entry point: `@vercel/analytics/next` - Added to the root layout file: `src/app/layout.tsx` - Positioned inside the body tag after the main layout structure, allowing it to track page views and user interactions across all routes ### Verification All checks completed successfully: - ✅ Build completed with no errors (`npm run build`) - ✅ Linting passed with no issues (`npm run lint`) - ✅ Type checking passed (`npm run type-check`) - ✅ Project compiles successfully with Analytics component integrated ### Notes - The Analytics component is now active and will automatically track page views, user interactions, and performance metrics - No breaking changes to existing functionality - All existing code structure and styling preserved - The component will work seamlessly with the existing theme provider and layout structure Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
1 parent 38c397e commit 1e9ed91

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@radix-ui/react-navigation-menu": "^1.2.14",
1919
"@radix-ui/react-slot": "^1.2.3",
2020
"@radix-ui/react-toast": "^1.2.15",
21+
"@vercel/analytics": "^1.6.1",
2122
"class-variance-authority": "^0.7.1",
2223
"clsx": "^2.1.1",
2324
"gray-matter": "^4.0.3",

src/app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata } from "next";
22
import { Geist, Geist_Mono } from "next/font/google";
33
import "./globals.css";
4+
import { Analytics } from "@vercel/analytics/next";
45
import { Header } from "@/components/layout/header";
56
import { Footer } from "@/components/layout/footer";
67
import { SkipLinks } from "@/components/ui/skip-links";
@@ -64,6 +65,7 @@ export default function RootLayout({
6465
<Footer />
6566
</div>
6667
</ThemeProvider>
68+
<Analytics />
6769
</body>
6870
</html>
6971
);

0 commit comments

Comments
 (0)