Skip to content
janturskyPublic

About

Privacy-first, cookieless web analytics you host yourself. Hono server for Cloudflare Workers, Vercel, Bun and Node; D1, Postgres and SQLite storage; a tiny tracker, React bindings, revenue tracking and an embeddable dashboard.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Analytik: simple, private, fast web analytics

npm CI coverage types license

Docs · Demo · npm · Changelog

Analytik

Web analytics you host yourself. The default strict mode is designed to avoid needing a cookie banner (see the privacy page for the conditions). A Hono server for Cloudflare Workers, Vercel, Railway, Bun or Node, storage on D1, Postgres (Supabase) or SQLite, a 4 KB tracker, React bindings and a dashboard you can embed.

The Analytik dashboard: visitors, revenue and a breakdown by source, page and device

The live view: a map of who is on the site now and what they just did Revenue: totals, revenue over time, revenue by channel and the payments list

It works on a phone too: the toolbar, the summary and the tables adapt to a narrow screen and a display cutout.

The Analytik dashboard on a phone: the view list, the toolbar and the summary in two columns

The demo also shows how each privacy mode works and a shop wired up with the React bindings.

What you get

  • Strict mode by default. The tracker stores no identifier on the visitor's device and no IP address is kept. The visitor id is a pseudonymous hash of IP, user agent and site, salted with a random value that is removed from the live database once the next month starts. Do Not Track visitors are still counted, in strict mode. Strict mode is designed to avoid needing consent, which is not legal advice.
  • Two more modes when you need them. enriched adds a per-tab id after the visitor consents. persistent uses first-party cookies like most analytics tools do, and should be treated as needing consent in the EU.
  • Revenue. A payments API with refunds, optional Stripe, Dodo, Lemon Squeezy, Paddle, Polar, Razorpay, Creem and Gumroad webhook adapters, and attribution to the visit that brought the buyer.
  • Goals, funnels, campaigns, realtime, JSON and CSV export, retention, share links (read-only, named, with expiry and revoke), notes on charts, CSV and PNG export.
  • Framework guides. Mount the server in Next.js, Express, Nuxt, SvelteKit, Astro or Cloudflare Pages, and fix common setup problems with the troubleshooting page.
  • A Mac menu bar app. Visitors online next to an icon, today's numbers and a chart one click away, for one or several sites, read with a revocable share link. Install it with npx analytik menubar; see the guide.
  • Bring your history. Import the visits and events of Umami, Simple Analytics, Matomo, GoatCounter, Google Analytics 4 or PostHog from Settings or with analytik import. A repeated import adds nothing, and an import can be removed without touching what Analytik tracked.
  • One server, three databases. It runs on D1, Postgres and SQLite, and the tests run every case against each of them.

Install

bun add analytik hono

Mac menu bar app

The Analytik Menu Bar app icon Visitors online next to an icon in the menu bar, today's numbers and a chart one click away, for one or several sites. It reads with a revocable share link and needs macOS 14 or later.

npx analytik menubar

Or download the zip from the releases. More in the guide.

A server in a dozen lines

import { createAnalytik } from 'analytik/server'
import { d1Storage } from 'analytik/storage/d1'

interface Env {
  DB: Parameters<typeof d1Storage>[0]
  ADMIN_PASSWORD: string
  SESSION_SECRET: string
}

export default {
  fetch(request: Request, env: Env) {
    const { app } = createAnalytik({
      storage: d1Storage(env.DB),
      admin: { password: env.ADMIN_PASSWORD, secret: env.SESSION_SECRET },
    })
    return app.fetch(request, env)
  },
}

Then add the tracker to your site:

<script defer src="https://analytics.example.com/js/analytik.js" data-site="my-site" data-mode="strict"></script>

Track an event or a sale from your own code:

import { createClient } from 'analytik/client'

const analytik = createClient({ site: 'my-site', api: 'https://analytics.example.com/api' })

analytik.track('signup', { plan: 'pro' })
analytik.revenue('purchase', 49.9, { currency: 'EUR', orderId: '1042' })

How it works

  1. The tracker (packages/analytik/src/tracker) sends pageviews, engaged time, outbound clicks and your events to POST /api/event, using a text/plain beacon so no preflight is needed.
  2. The server (packages/analytik/src/server) checks the origin against the site's domain, drops bots, and computes the visitor id with the monthly salt.
  3. Sessions, events and payments land in the storage adapter you chose (packages/analytik/src/storage).
  4. Payments arrive through POST /api/v1/payments or a provider webhook (packages/analytik/src/adapters) and are matched to the visit that led to them.
  5. The dashboard (packages/analytik/src/dashboard) reads the admin API. Embed <Dashboard /> in your own app or use the one in the demo.

Deploy

Where Storage Good for
Cloudflare Workers D1 The free plan, no server to run (below)
Vercel Supabase or Neon Postgres Already hosting your site on Vercel
Railway Railway Postgres A long-running service with a database
Bun or Node SQLite file A VPS or a Docker container

Cloudflare in one command

npx analytik@latest create my-stats

It installs the packages, signs you in to Cloudflare, creates the D1 database, deploys a Worker that serves the dashboard, the tracker and the API, and sets the secrets. You get the address and a dashboard password at the end: open it, sign in, add your site and paste the snippet. A small site fits Cloudflare's free plan.

Prefer to click?

Cloudflare (Workers and D1)
Deploy to Cloudflare

Vercel (a function with Postgres)
Deploy with Vercel

The Cloudflare button copies the template to your GitHub and deploys it, and asks for two values on its screen: ADMIN_PASSWORD (the password you will sign in with) and SESSION_SECRET (32 or more random characters, openssl rand -hex 32). The Vercel one does the same for a function with Postgres (Supabase or Neon) and asks for the connection string and the two secrets. npx analytik@latest create my-stats --target vercel writes the Vercel project to deploy yourself.

The Worker is a few lines. The dashboard is built into analytik/standalone, so there is no app to build:

import { createAnalytik } from 'analytik/server'
import { withDashboard } from 'analytik/standalone'
import { d1Storage } from 'analytik/storage/d1'

interface Env {
  DB: D1Database
  ADMIN_PASSWORD: string
  SESSION_SECRET: string
}

let handler: ReturnType<typeof withDashboard<[Env, ExecutionContext]>> | undefined

export default {
  fetch(request: Request, env: Env, ctx: ExecutionContext) {
    handler ??= withDashboard(
      createAnalytik({
        storage: d1Storage(env.DB),
        admin: { password: env.ADMIN_PASSWORD, secret: env.SESSION_SECRET },
      }).app,
    )
    return handler.fetch(request, env, ctx)
  },
}

The Cloudflare guide has the manual steps, a custom domain, the free-plan limits and a first-party route for ad blockers. To put the dashboard inside your own React app instead, see embedding the dashboard.

Alternatives

Plausible and Umami are good, mature alternatives if you prefer a bigger project.

Support

Browsers: the tracker targets ES2020, so any evergreen browser. Runtimes: Cloudflare Workers, Bun 1.3+, Node 22.19+, Vercel Functions. The dashboard and React bindings need React 19.

Development

bun install
bun run check      # samples, format, lint, typecheck, tests with coverage
bun run dev        # the demo app
bun run dev:docs   # the docs site

See CONTRIBUTING.md. Security notes are in SECURITY.md.

Other Projects & Products

GitHub Profile
GitHub Profile

Open-source repositories & code
LoupeKit
LoupeKit

Tech stack, design tokens, AI code checker
TextArray
TextArray

Online text transformation tool
AddonHive
AddonHive

Addons & integrations hub
Mobile Games & Apps
Mobile Games & Apps

Android & iOS Applications
And more
And more

More projects, writing & contact

License

MIT

Country flags are from Circle Flags by HatScripts (MIT), see THIRD_PARTY_NOTICES.md.

About

Privacy-first, cookieless web analytics you host yourself. Hono server for Cloudflare Workers, Vercel, Bun and Node; D1, Postgres and SQLite storage; a tiny tracker, React bindings, revenue tracking and an embeddable dashboard.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages