Skip to content

Commit 946fff6

Browse files
committed
feat: enable Vercel Web Analytics in production
1 parent 7c1c7bc commit 946fff6

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Alexandre Perronnet
22

3-
Source for [www.alexperronnet.com](https://www.alexperronnet.com), a static personal website built with Astro, TypeScript, and Tailwind CSS. The site serves pre-rendered HTML, self-hosted Schibsted Grotesk, and small browser scripts for ages and local time. It has no backend, analytics, cookies, or third-party requests during page load.
3+
Source for [www.alexperronnet.com](https://www.alexperronnet.com), a static personal website built with Astro, TypeScript, and Tailwind CSS. The site serves pre-rendered HTML, self-hosted Schibsted Grotesk, and small browser scripts for ages and local time. Vercel Web Analytics records production page views. There is no application backend.
44

55
## Requirements
66

@@ -68,6 +68,14 @@ This is a manually maintained estimate for the tested homepage, not a live measu
6868

6969
The custom 404 has `noindex, nofollow`. When `VERCEL_ENV=preview`, pages also receive `noindex, nofollow` and robots.txt disallows crawling. These directives control indexing; they do not restrict access.
7070

71+
## Web Analytics
72+
73+
The shared layout includes the official `@vercel/analytics/astro` component when `VERCEL_ENV=production`. It records page views on pages using that layout, including the 404 page. Local development, local builds, and preview deployments do not initialize analytics.
74+
75+
Enable Web Analytics in the Vercel project dashboard, then deploy. Vercel provides the tracking script and ingestion endpoints on the site's own origin. No API key, custom event tracking, or additional server integration is required.
76+
77+
After deployment, visit the public site and check the project's Analytics tab. Data can take a short time to appear, and content blockers may prevent collection. The analytics script adds network requests; the dated carbon assessment above reflects the version tested and should be reviewed after changes.
78+
7179
## Deployment
7280

7381
The GitHub repository is connected to the Vercel project `alexperronnet.com`. Pushes to the production branch, `main`, trigger production deployments; other branches can receive preview deployments through the Git integration.
@@ -98,7 +106,7 @@ No application secrets or local `.env` file are required. Enable automatic expos
98106
| Variable | Usage |
99107
| --- | --- |
100108
| `VERCEL_GIT_COMMIT_SHA` | Builds the public GitHub commit link after validating the full SHA; absent locally, where the footer shows `Build local` |
101-
| `VERCEL_ENV` | Excludes preview deployments from indexing |
109+
| `VERCEL_ENV` | Excludes preview deployments from indexing and enables analytics only in production |
102110

103111
The GitHub repository must remain public for visitors to follow the Build link.
104112

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@astrojs/sitemap": "3.7.4",
2020
"@fontsource-variable/schibsted-grotesk": "5.3.0",
2121
"@tailwindcss/vite": "4.3.3",
22+
"@vercel/analytics": "2.0.1",
2223
"astro": "7.3.3",
2324
"tailwindcss": "4.3.3"
2425
},

‎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.

‎src/layouts/page.astro‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import "@fontsource-variable/schibsted-grotesk/wght.css";
33
import "#src/styles/global.css";
4+
import Analytics from "@vercel/analytics/astro";
45
import { site } from "#src/config/site.ts";
56
67
interface Props {
@@ -72,5 +73,6 @@ const structuredData = {
7273
</main>
7374
<slot name="footer" />
7475
</div>
76+
{import.meta.env.VERCEL_ENV === "production" && <Analytics />}
7577
</body>
7678
</html>

0 commit comments

Comments
 (0)