Web Analytics for AI Coders
Know who visits your site, what they click, and where they leave. Analytics turns guesswork into real answers.
In this chapter
- What analytics tools track and why every site needs one
- How to read visitor numbers, bounce rate, and traffic sources
- How to ask AI to set up Plausible, Vercel Analytics, or PostHog
- What to actually do with the data once you start collecting it
Why Add Analytics?
Without analytics, you're building in the dark. You have no idea if anyone is visiting, what they like, or where they get stuck.
Analytics Platforms
Pick one to start with. You can always switch or add more later.
If your site is on Vercel, this is the easiest option. One click to enable. Shows page views, visitors, top pages, and Web Vitals performance scores.
Best if you already deploy on Vercel. No extra accounts needed.
The most widely used analytics tool. Very detailed data about visitors, sessions, traffic sources, and user behavior. Can be overwhelming for beginners.
Most powerful option, but has a learning curve. Good if you want deep data.
Goes beyond page views. See session recordings of real users, track custom events, run A/B tests, and build funnels. Open source and generous free tier.
Great if you want to see exactly how users interact with your site.
Simple, lightweight, and doesn't use cookies. GDPR compliant out of the box. Shows you the essentials without the complexity. Open source.
Best if you care about user privacy and want a clean, simple dashboard.
Setting Up Analytics
You don't need to understand the technical details. Just tell your AI tool which platform you want, and it will handle the rest.
“Add Vercel Analytics to my Next.js project. Install the package and add the Analytics component to my root layout. I want to track page views and Web Vitals.”
“Add Google Analytics (GA4) to my Next.js project. My measurement ID is G-XXXXXXXXXX. Add the tracking script to my root layout and make sure it works with client-side navigation. Don't track users until they accept cookies.”
“Add PostHog analytics to my Next.js project. Set up the PostHog provider in my layout, configure it to track page views automatically, and show me how to track custom events like button clicks.”
“Add Plausible Analytics to my Next.js project. Add the lightweight script tag to my root layout. My domain is mydomain.com. Make sure it tracks page views on client-side navigation.”
Key Metrics to Track
Here are the numbers that actually matter for most websites.
Privacy & GDPR Basics
If your site has visitors from Europe (and it probably does), you need to follow some rules about tracking.
Prompt This
Copy-paste these prompts into your AI tool to apply what you just learned.
“Add Google Analytics to my Next.js app. Track page views automatically and set up custom events for [button clicks / form submissions / sign-ups].”
“Add a simple analytics dashboard to my admin panel that shows [total users, page views this week, most popular pages] using data from my database.”
Frequently Asked Questions
Which analytics tool should I use?
Vercel Analytics is the easiest if you're deployed on Vercel: zero configuration. Google Analytics is the most comprehensive and free. Plausible and Fathom are privacy-friendly alternatives that don't need cookie banners. For most projects, Vercel Analytics or Plausible is the simplest choice.
Do I need a cookie consent banner?
If you use Google Analytics or any tool that tracks users with cookies, yes. GDPR and similar laws require consent. Privacy-friendly tools like Plausible, Fathom, and Vercel Analytics don't use cookies, so they don't need consent banners.
What metrics actually matter?
For most sites: page views (how many people visit), bounce rate (how many leave immediately), and top pages (what content people care about). For apps: also track signups, feature usage, and retention. Don't track everything: focus on metrics that inform decisions.