<Analytics /> mount in the root layout that fans out to
seven analytics providers, plus a metadata.verification block that emits
the three search-engine ownership meta tags. Every loader / tag checks its own
env var and renders nothing when unset, so you only pay for what you’ve
configured. No re-architecting required to add or drop a provider — set the
env var, restart, done.
Analytics providers
Prerequisites
- An account with at least one of: Vercel, Google Analytics 4, PostHog, Plausible, Umami, Microsoft Clarity, or Yandex Metrika.
- The site / property / website ID from that provider’s dashboard.
- A production domain (some providers reject events from
localhostor sample them out).
Step-by-step
-
Pick which providers you want in
src/config/site.ts. All seven aretrueby default; flip tofalseto disable even if the env var is set. -
Add the matching env vars to
.env.local. All areNEXT_PUBLIC_*— the loader runs in the browser so they must ship to the client bundle. -
Vercel Analytics is zero-config when deployed on Vercel — the
@vercel/analytics/nextcomponent auto-injects the script. Locally it’s a no-op. Disable by settinganalytics.vercel = false. -
Restart
pnpm dev—NEXT_PUBLIC_*env vars are baked at build time.
Pick the right provider
| Provider | When to pick |
|---|---|
| Vercel Analytics | You’re on Vercel and want a zero-config baseline. Free tier is plenty. |
| GA4 | You need attribution into Google Ads / a marketing team that already uses it. |
| PostHog | Product analytics, feature flags, session replays — all in one. Generous free tier. |
| Plausible | Privacy-first, GDPR-friendly, no cookie banner needed. Lightweight script. |
| Umami | Open-source, self-hostable. Same privacy story as Plausible but free if you self-host. |
| Microsoft Clarity | Heatmaps + session recordings, free with no traffic cap. Pairs well with GA4. |
| Yandex Metrika | Free analytics + heatmaps + session recordings. Strong in RU/CIS markets. |
Verify it works
- Open the site in an incognito window.
- Open devtools → Network and filter by the provider’s hostname (e.g.
posthog.com,plausible.io,clarity.ms,mc.yandex.ru). You should see at least one request fire on page load. - Click around — each provider’s dashboard should show a real-time visitor within 30 seconds.
- View the page source: you should see one
<script>tag per enabled provider, none for disabled ones.
Common pitfalls
- Missing
NEXT_PUBLIC_prefix. Anything the browser reads needs the prefix. Without it, Next.js strips the variable from the client bundle and the loader silently mounts asnull. - Ad-blockers eating your scripts. uBlock Origin and Brave block GA4,
PostHog, Clarity, Yandex Metrika, and Umami by default. To recover, use a
proxy domain — Plausible supports a
/js/script.outbound-links.jsself-host route, and PostHog has a reverse-proxy guide. - GA4 needs an EU consent banner. GDPR requires explicit opt-in for GA4 tracking. Same for Clarity and Yandex Metrika (session replay = personal data). Either gate the script behind a consent prompt or use Plausible / Umami which are cookie-free by design.
- Dashboard pollution from localhost. Dev traffic shows up in production
dashboards if you don’t filter it. Either set
analytics.posthog = falsein dev, or use the providers’ “exclude IP” / “disable on localhost” filters. - Plausible domain mismatch.
NEXT_PUBLIC_PLAUSIBLE_DOMAINmust exactly match the site you registered in Plausible — including or excludingwww. Mismatched events are dropped silently. - Yandex Metrika counter id is digits only. Don’t paste the whole snippet
— only the numeric
ym(NUMBER, ...)value goes in the env var.
Search-engine site verification
To prove ownership in Google Search Console, Bing Webmaster Tools, or Yandex Webmaster, each console asks you to add a meta tag to your site’s<head>. vibestrap renders these via Next.js metadata.verification in
src/app/layout.tsx, so you just paste the value into an env var.
Step-by-step
-
Add your domain in each console:
- Google Search Console → search.google.com/search-console
- Bing Webmaster Tools → bing.com/webmasters
- Yandex Webmaster → webmaster.yandex.com
-
Pick the “HTML tag” verification method in each console. You’ll see a
meta tag like:
-
Copy ONLY the
contentvalue (not the whole tag) into.env.local:These are server-side env vars (noNEXT_PUBLIC_prefix) — Next.js reads them when generating the root metadata at build time. -
Toggle individual tags in
src/config/site.tsif you want to suppress one even though the env var is set: - Deploy, then click Verify in each console.
Verify it works
<meta> tag per env var that’s set. Empty env vars produce
no tag (no empty content="" pollution).
Common pitfalls
- Don’t paste the whole
<meta>tag — only thecontentvalue. Pasting the tag itself produces broken HTML in the rendered head. - Verification is one-time. Once the console confirms, you can leave the env var set; it doesn’t cost anything to keep the meta tag rendered.
- CDN cache. If you deploy and the console says “tag not found”, purge your CDN cache (Cloudflare, Vercel) — the verifier hits the live HTML.
- DNS is an alternative. All three consoles also support DNS TXT-record verification, which doesn’t touch your HTML. If you prefer that route, leave the env vars empty and add the TXT records in your DNS provider.
Official docs
- Vercel Analytics: vercel.com/docs/analytics
- Google Analytics 4: support.google.com/analytics
- PostHog: posthog.com/docs
- Plausible: plausible.io/docs
- Umami: umami.is/docs
- Microsoft Clarity: learn.microsoft.com/clarity
- Yandex Metrika: yandex.com/support/metrica
- Google Search Console: support.google.com/webmasters
- Bing Webmaster Tools: bing.com/webmasters/help
- Yandex Webmaster: yandex.com/support/webmaster