Add Vercel Web Analytics to Next.js
Implemented Vercel Web Analytics for Next.js
Summary:
Successfully installed and configured Vercel Web Analytics in this Next.js App Router project.
Changes Made:
1. Installed @vercel/analytics package:
- Added @vercel/analytics@^1.6.1 to package.json dependencies
- Updated package-lock.json with new dependency tree
2. Modified app/layout.tsx:
- Added import statement: import { Analytics } from '@vercel/analytics/next'
- Added <Analytics /> component inside the <body> tag, after <SpeedInsights />
- Maintained existing code structure and formatting
3. Verification:
- Build completed successfully with no errors (npm run build)
- No linting errors (no lint script configured in project)
- No test failures (no test script configured in project)
- All changes follow Next.js App Router best practices
Implementation Details:
- The Analytics component is placed at the end of the body tag, following the existing pattern used for SpeedInsights
- The component will automatically track page views and Web Vitals data
- Works seamlessly with the existing SpeedInsights integration
- No environment variables or additional configuration required
Files Modified:
- app/layout.tsx (added Analytics import and component)
- package.json (added @vercel/analytics dependency)
- package-lock.json (updated with new dependency tree)
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
This commit is contained in:
parent
104cef06d8
commit
204f3a1249
3 changed files with 42 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import Image from "next/image";
|
|||
import logo from "./logo.png"
|
||||
import Link from "next/link";
|
||||
import { SpeedInsights } from '@vercel/speed-insights/next';
|
||||
import { Analytics } from '@vercel/analytics/next';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Portfolio - Mike Karl",
|
||||
|
|
@ -34,6 +35,7 @@ export default function RootLayout({
|
|||
{children}
|
||||
<div className="bg" />
|
||||
<SpeedInsights />
|
||||
<Analytics />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
|
|
|||
39
package-lock.json
generated
39
package-lock.json
generated
|
|
@ -8,6 +8,7 @@
|
|||
"name": "portfolio",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@vercel/analytics": "^1.6.1",
|
||||
"@vercel/speed-insights": "^1.3.1",
|
||||
"framer-motion": "^12.33.0",
|
||||
"next": "^15.5.12",
|
||||
|
|
@ -1046,6 +1047,44 @@
|
|||
"@types/react": "^19.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vercel/analytics": {
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/analytics/-/analytics-1.6.1.tgz",
|
||||
"integrity": "sha512-oH9He/bEM+6oKlv3chWuOOcp8Y6fo6/PSro8hEkgCW3pu9/OiCXiUpRUogDh3Fs3LH2sosDrx8CxeOLBEE+afg==",
|
||||
"license": "MPL-2.0",
|
||||
"peerDependencies": {
|
||||
"@remix-run/react": "^2",
|
||||
"@sveltejs/kit": "^1 || ^2",
|
||||
"next": ">= 13",
|
||||
"react": "^18 || ^19 || ^19.0.0-rc",
|
||||
"svelte": ">= 4",
|
||||
"vue": "^3",
|
||||
"vue-router": "^4"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@remix-run/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@sveltejs/kit": {
|
||||
"optional": true
|
||||
},
|
||||
"next": {
|
||||
"optional": true
|
||||
},
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"svelte": {
|
||||
"optional": true
|
||||
},
|
||||
"vue": {
|
||||
"optional": true
|
||||
},
|
||||
"vue-router": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vercel/speed-insights": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/speed-insights/-/speed-insights-1.3.1.tgz",
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/analytics": "^1.6.1",
|
||||
"@vercel/speed-insights": "^1.3.1",
|
||||
"framer-motion": "^12.33.0",
|
||||
"next": "^15.5.12",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue