Vite analytics with Dataflare: setup in two minutes

Single-page apps built with Vite (React, Vue, Svelte, Solid) can use the npm package instead of a script tag, so types and tree-shaking come with it.

Dataflare is open-source analytics that runs in your own Cloudflare account: web analytics, product analytics (trends, funnels, retention), session replay, feature flags and A/B tests. There is no Dataflare service to sign up for. Your events go to a Worker and a D1 database in your account.

1. Deploy Dataflare

From your project's root, with a Cloudflare API token:

CLOUDFLARE_API_TOKEN=… npx dataflare-cli init

dataflare init detects Vite from your package.json, creates the database, the replay bucket and the Worker, and prints the snippet below with your real host and project filled in. It also writes AGENTS.md, a Claude Code skill and .mcp.json, so your coding agent can do the next steps for you.

2. Add the snippet

In src/main.ts (or main.tsx) — after npm install dataflare-web``:

import { glass } from 'dataflare-web';

glass.init({ host: 'https://glass.<you>.workers.dev', project: 'my-app' });

Page views, clicks, JavaScript errors and Core Web Vitals start arriving straight away.

3. Track what matters

import { glass } from 'dataflare-web';

glass.capture("signup_completed", {"plan":"pro"});

After someone signs in, link their visits to their account so funnels span the moment of signup:

glass.identify(user.id, { plan: user.plan });

Name events object_action in the past tense (signup_completed, invite_sent) and put details in properties, never personal data.

4. Check it works

npx dataflare-cli status
npx dataflare-cli events signup_completed

Then open https://glass.<you>.workers.dev/app (sign in with npx dataflare-cli key), or ask your agent: "Which traffic source converts best to signup?"

Serve it from your own domain

Ad blockers often block third-party analytics domains. Serve Dataflare from a path on your own site instead, if your domain is on Cloudflare:

npx dataflare-cli init --route example.com

Then use https://example.com/_glass as the host in the snippet.

Next