# How to Vibe Code Your Own Simple Analytics (and Stop Paying for It)

> Privacy-first web analytics platform

- Site: https://simpleanalytics.com
- Category: Analytics
- Verdict: **Solid side project** (75/100 vibecodeable)
- Estimated effort: 2-3 weeks part-time

## Verdict

Build a personal-use subset of this tool; the single biggest catch is engineering an efficient ingestion endpoint that aggregates high-volume pageview events without choking a standard database.

A personal analytics clone is an achievable side project. The core loop consists of a tiny tracking script executing a fetch request, an endpoint parsing headers to extract referrers and countries without storing IPs, and a simple dashboard charting the aggregated metrics. The primary engineering challenge lies in database performance under continuous write load, which requires proper time-series indexing or pre-aggregation tables rather than raw row counts.

### What you can't replicate

- Official GDPR legal standing and brand trust
- Enterprise compliance certifications (SOC 2)
- Existing user base and integrations ecosystem

## What it does

A privacy-friendly alternative to Google Analytics that tracks pageviews, events, and referrers without cookies, personal data, or visitor consent banners.

### Core features

- Lightweight JavaScript tracking snippet for client-side event ingestion
- Privacy-first endpoint parsing country from IP headers without storing personal data
- Aggregated analytics dashboard displaying pageviews, referrers, and events
- Date-range filtering and custom event tracking
- First-party proxy routing capability to bypass ad blockers
- API endpoints for exporting traffic stats

## The business

### Pricing

- Free Tier: Free — For hobby sites with limited history and badge requirement.
- Self-Serve Paid: $20/mo — Dynamic pricing based on pageview volume, starting at 100k pageviews/month.
- Enterprise: Custom — For organizations requiring raw exports, data warehouse integrations, and SSO.

Founded 2018.
Team size: 1-3.

## The hard parts

- High-throughput event ingestion handling traffic spikes without locking transactional databases
- Efficient aggregation pipelines for calculating pageview counts and time-series metrics over large datasets
- Bypassing ad-blockers reliably via first-party DNS proxy configuration

## How to vibe code Simple Analytics

### Prerequisites

- Node.js (free): Required for running the full-stack development environment.
- GitHub (free): Source control and deployment pipeline integration.

### Recommended AI tools

- Cursor: Ideal for iterative full-stack development and reviewing component diffs for the dashboard UI.
- Claude Code: Effective for scaffolding the ingestion API routes and database schemas.

### Stack

- Frontend: Next.js
- Backend: Next.js API Routes
- Database: Turso
- Auth: better-auth
- Payments: None
- Other: Tailwind CSS, Recharts

### Hosting

- Cloudflare (Hosting the frontend dashboard and edge ingestion endpoint workers): $0-5/mo

### Build guide

1. **Project Scaffolding & Database Schema** — Initialize the Next.js project with Tailwind CSS and set up the Turso database schema for storing aggregated and raw event hits.

```
Create a new Next.js project using TypeScript and Tailwind CSS. Configure Turso as the SQLite database client using libSQL. Define a schema for users, websites, and events. The events table should store columns for website_id, pathname, referrer, browser, os, country, and timestamp without capturing any IP addresses or personal identifiers. Ensure proper indexes are created on timestamp and website_id for performant queries.
```

2. **Authentication System Setup** — Integrate better-auth for secure single-user access to the analytics dashboard.

```
Install and configure better-auth in the Next.js application using the Turso database adapter. Set up email and password authentication with secure session management cookies. Create sign-in and sign-up pages with Tailwind styling and protect dashboard routes behind an authentication middleware.
```

3. **Ingestion Endpoint & Privacy Filtering** — Build the lightweight tracking endpoint that ingests pageviews while strictly scrubbing personal data and deriving location from request headers.

```
Create an API route at /api/collect that accepts POST requests from the tracking script. Extract the pathname, referrer, and user-agent string. Derive the country code safely from standard proxy headers (like CF-IPCountry or equivalent) without storing the raw IP address. Validate that the website_id exists in the database, sanitize all incoming strings, and efficiently insert the event record into the Turso database. Ensure CORS headers are properly set to allow cross-origin tracking requests.
```

4. **Client-Side Tracking Script** — Develop the lightweight JavaScript snippet that customers embed on their websites to fire pageview events.

```
Write a tiny, dependency-free vanilla JavaScript tracking snippet (under 2KB) that automatically captures page loads and single-page application route changes using the History API. The script should read document.location.pathname and document.referrer, and send a lightweight fetch request to the /api/collect endpoint with the target website identifier. Ensure it operates entirely without setting cookies or local storage.
```

5. **Dashboard Analytics UI & Aggregation Queries** — Build the main analytics dashboard featuring visitor counts, top pages, referrers, and country breakdowns using charts.

```
Build a responsive analytics dashboard in Next.js that displays metrics for a selected website. Create server actions or API endpoints that query the Turso database to aggregate pageviews, unique visitors (estimated via privacy-safe daily rolling hashes), top pages, top referrers, and countries over custom date ranges. Integrate Recharts to render clean time-series charts for pageview trends. Include a website switcher and a settings tab to generate tracking snippets.
```

6. **Polish & Edge Deployment** — Finalize UI polish, configure error monitoring with Sentry, and deploy the application to Cloudflare Workers or Pages.

```
Audit the Next.js application for performance and responsive layout issues. Add error tracking with Sentry. Configure the project for deployment on Cloudflare using the appropriate adapter, verifying that environment variables for Turso database connections are correctly set up on the edge.
```

### Cost vs paying

**Starting costs (one-time):**

- Custom Domain (optional): $12/yr
- Total: ~$12 one-time

**Ongoing costs (monthly):**

- Cloudflare & Turso Free Tiers: $0/mo
- Total: $0/mo

- Paying for the SaaS instead: $20/mo
- Build time: 25-35 hours
- AI tool credits: $20
- Break-even: 0 months

## Sources

- [Simple Analytics Website](https://simpleanalytics.com)
- [TrustMRR - Simple Analytics Metrics](https://trustmrr.com/startup/simple-analytics)