Skip to content

Commit 0400f7d

Browse files
committed
Install Vercel Web Analytics in Next.js
Implemented Vercel Web Analytics for Next.js App Router ## Summary Successfully installed and configured @vercel/analytics for the Coffee Timer Next.js application which uses the App Router architecture with internationalization (i18n). ## Changes Made ### 1. Package Installation - Installed `@vercel/analytics` version 1.6.1 using pnpm - Updated `package.json` to include the new dependency - Updated `pnpm-lock.yaml` with the new package and its dependencies ### 2. Analytics Integration Modified: `app/[locale]/layout.tsx` - Added import statement: `import { Analytics } from '@vercel/analytics/next'` - Added `<Analytics />` component inside the `<body>` tag, after the `<LayoutBody>` component and `{children}` ## Implementation Details The project uses Next.js App Router with a locale-based routing structure. The main layout is located at `app/[locale]/layout.tsx` rather than the root `app/layout.tsx` (which is minimal due to the locale segment). The Analytics component was placed inside the body tag to ensure it's included on all pages across all locale routes. This placement follows Vercel's best practices for App Router implementations. ## Verification ✅ Build: Successfully compiled with `pnpm run build` ✅ TypeScript: Passed type checking with `pnpm run typecheck` ✅ Linting: Passed ESLint checks with `pnpm run lint --max-warnings=0` ✅ Dependencies: Lock file properly updated ## Files Modified - `app/[locale]/layout.tsx` - Added Analytics import and component - `package.json` - Added @vercel/analytics dependency - `pnpm-lock.yaml` - Updated with new package dependencies The implementation is complete and ready for deployment. The Analytics component will automatically track page views and Web Vitals when deployed to Vercel. Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
1 parent 0ab72ef commit 0400f7d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

app/[locale]/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 { getMessages, getTimeZone, setRequestLocale } from 'next-intl/server'
33
import { notFound } from 'next/navigation'
4+
import { Analytics } from '@vercel/analytics/next'
45
import { routing } from '@/i18n/routing'
56
import { LayoutBody } from '@/components/LayoutBody'
67
import '../globals.css'
@@ -151,6 +152,7 @@ export default async function LocaleLayout({
151152
>
152153
{children}
153154
</LayoutBody>
155+
<Analytics />
154156
</body>
155157
</html>
156158
)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@radix-ui/react-dialog": "^1.1.15",
2929
"@radix-ui/react-select": "^2.2.6",
3030
"@radix-ui/react-slider": "^1.3.6",
31+
"@vercel/analytics": "^1.6.1",
3132
"framer-motion": "^12.23.25",
3233
"lucide-react": "^0.555.0",
3334
"next": "^16.0.7",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)