Grosslytics

How to Self-Host Revenue Analytics on Cloudflare D1

Deploy Grosslytics on Cloudflare Workers and D1 in five steps. Understand free-tier limits, queue costs, prebuilt and source install paths, and verification.

Deploy Grosslytics on your own Cloudflare account in five steps using npx grosslytics@latest install --free (or bun run setup from source), then check your Workers, D1, and Queues free-tier budgets before sending live traffic. Queues hit the free ceiling first: 10,000 daily operations cover about 3,333 queued events per day before you need the $5/month Workers Paid plan.

Key takeaways

  • Monitor every Cloudflare service meter: Workers, D1 (500 MB per database on Free), Queues (10,000 operations/day), and Durable Objects.
  • Install the prebuilt free release with npx grosslytics@latest install --free, or build from source with bun run setup.
  • Queues are usually the first free-tier ceiling: 10,000 daily operations cover roughly 3,333 queued events per day before retries.
  • Verify browser events (202 Accepted), queue delivery, and one signed test payment before relying on reports.

Cloudflare’s allowances below were verified on November 21, 2026. Check your account usage if other Workers share the same account budgets.

Step 1: Check whether your workload fits the free plan

Grosslytics uses two Workers, a D1 SQLite database, a Queue with a dead-letter queue, and a SQLite-backed Durable Object (SiteLiveHub) for live visitor presence.

Component Free allowance relevant to this setup What to monitor
Workers 100,000 requests/day; 10 ms CPU time per invocation API requests, dashboard queries, and CPU time
D1 5M rows read/day, 100,000 rows written/day; 500 MB per database (5 GB account max) Query row scans, index writes, and grosslytics-db size
Queues 10,000 standard operations/day Write, read, and delete operations (3 per message) plus retries
Durable Objects 100,000 requests/day; 13,000 GB-s/day duration Live presence updates and WebSocket connections

Check current Workers pricing, D1 pricing, Queues pricing, and Durable Objects pricing before deploying high-traffic sites. Because Grosslytics stores visits and payments in one D1 database, plan around the 500 MB per-database cap and configure visit data retention under Settings if needed.

Cloudflare D1 billing table showing free daily reads, writes and total storage limits.
Cloudflare's public D1 pricing documentation shows the database allowance. Captured 2026-11-08. Source: Cloudflare D1.

Estimate your daily Queue operations first

Each accepted browser event sends one Queue message, which consumes three standard operations (write, read, and delete):

Queue operations = 2,000 events * 3 operations = 6,000/day
Remaining queue allowance = 10,000 - 6,000 = 4,000/day
Idealized free queue ceiling = floor(10,000 / 3) = 3,333 events/day

Because pageviews, leave events (read time and scroll depth), and goal clicks each generate an event, 3,333 events correspond to roughly 1,000 to 1,500 pageviews/day. Above that traffic, Cloudflare’s Workers Paid plan ($5/month base) lifts Queue and D1 ceilings.

Step 2: Prepare your account and analytics hostname

Use a Cloudflare account that manages your domain, an unused subdomain such as analytics.example.com, and Node.js 22.12+ (or Node.js 22.23.4+, Git, and Bun for source builds).

For a brand-new Cloudflare account, open Workers & Pages in the Cloudflare Dashboard once so your workers.dev subdomain initializes. Check that analytics.example.com has no conflicting A, AAAA, or CNAME records before running the installer.

Step 3: Deploy the API, dashboard, and database

Run the CLI installer from a dedicated working directory:

npx grosslytics@latest install --free

For Lifetime licenses (no footer attribution link required), use npx grosslytics@latest install --lifetime. To build from a source checkout, follow the source installation instructions.

The installer asks for your hostname, Cloudflare zone, and dashboard password, then creates grosslytics-db and both queues. After running D1 migrations, it deploys the API and web Workers onto that hostname so /api/*, /g.js, and /app share one origin. Keep your generated grosslytics-install directory private and store the printed API_TOKEN in a password manager.

To install new releases later, run npx grosslytics@latest update from that same folder (or git pull && bun run setup for source builds).

Step 4: Add your site and install the tracker

Open https://analytics.example.com/app, sign in, and register the domain you want to track. Copy the generated site ID and paste the tag into your site’s <head>:

<script
  defer
  src="https://analytics.example.com/g.js"
  data-site-id="YOUR_SITE_ID"
></script>

If you used --free, add the "Powered by Grosslytics" link inside your tracked site’s homepage footer (rel="sponsored" or rel="nofollow" are both accepted) and click Verify so the dashboard opens.

Next, open https://www.example.com/?utm_source=setup-check&utm_medium=referral in a normal browser window. Skip headless WebDriver sessions, because g.js drops them as bots. If your site sends a Content Security Policy header, allow analytics.example.com in both script-src and connect-src per the tracker setup docs.

Symptom Where to check
g.js fails to load or no /api/event call appears Check script URL, data-site-id, and CSP console errors
/api/event returns 403 or 404 Verify tracked domain spelling and /api/* routing to the API Worker
/api/event returns 202, but visit is missing Inspect API Worker logs, grosslytics-ingest queue depth, and dead-letter queue errors

Step 5: Connect payments and verify revenue attribution

Configure your webhook destination and signing secret under Payments in your dashboard:

https://analytics.example.com/api/webhooks/PROVIDER?siteId=YOUR_SITE_ID

Follow the setup guide for your payment provider: Stripe, Paddle Billing, Polar & Dodo Payments, or Razorpay. Send one sandbox or test purchase from a tagged URL and confirm the sale credits your UTM source in the expected currency.

Grosslytics public demo with sample visitor, net revenue and traffic-source charts.
The Grosslytics public demo shows the dashboard with sample data. Captured 2026-11-08. Source: Grosslytics.

Check a test payment

Check the first visit and the first payment separately. If the visit never appears, verify the hostname, site ID and script requests before troubleshooting webhook signatures. After connecting a payment provider, match the test charge to the sale before comparing totals.

Open the Cloudflare deployment step or open Stripe payment setup. See the closed Stripe sandbox example for a worked example of comparing charges, refunds and fees.

What should you monitor after launch?

Watch D1 > Metrics > Row Metrics alongside your Queue backlog and Worker CPU. Grosslytics queries raw event rows for custom date ranges and filters. On busy free-tier sites, set Keep visit data (90 days to 2 years) under Settings so old visits roll off. Once traffic passes the free limits, move to Workers Paid ($5/month) or switch to Hosted Cloud or Lifetime. See also how Grosslytics compares with Docker-based self-hosted tools in PostHog vs Grosslytics and Plausible vs Grosslytics.

Frequently asked questions

Is Cloudflare D1 enough for self-hosted web analytics?

D1 handles relational storage for visits, sessions, and payments, while Workers serve ingest and dashboard APIs, Queues buffer write bursts, and a Durable Object drives live presence. All four components fit in one Cloudflare account.

Can this run with no monthly server bill?

Yes, for sites within Cloudflare’s Free plan limits (around 1,000-1,500 pageviews/day given Queue operation counts). Above that volume, Cloudflare’s $5/month Workers Paid plan lifts the 10,000/day Queue cap and raises D1 read and write limits.

Can I upgrade from free self-hosting to Lifetime later?

Yes. Installing with --free and --lifetime deploys the same stack on your Cloudflare account. Applying a Lifetime license removes the footer link requirement and adds commercial usage rights without touching your database.