<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz" -->

---
title: First-party analytics with SQLite | daily.dev
description: A practical walkthrough of building first-party product analytics using a single SQLite events table on Cloudflare D1, replacing Google Analytics. Covers the...
canonical: https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: First-party analytics with SQLite | daily.dev
og:description: A practical walkthrough of building first-party product analytics using a single SQLite events table on Cloudflare D1, replacing Google Analytics. Covers the...
og:url: https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz
og:image: https://api.daily.dev/og/posts/P5rK4jWPz.png
og:image:alt: First-party analytics with SQLite
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# First-party analytics with SQLite

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 4 min read · 1 upvotes · 0 comments

## Summary

A practical walkthrough of building first-party product analytics using a single SQLite events table on Cloudflare D1, replacing Google Analytics. Covers the flat schema design, TypeScript event name whitelisting for both server-side tracking and client-side beacons using navigator.sendBeacon, campaign attribution via a cookie-stored src parameter, and simple funnel SQL queries. The approach trades session replay and geo dashboards for full data ownership, no third-party scripts, and no cookie banners.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/first-party-analytics-sqlite>

## Questions this post answers

### How can I track product analytics without using Google Analytics?

Build a single append-only SQLite events table with columns like id, name, src, anon_token, user_id, report_id, meta, and created_at, indexed on (name, created_at). Whitelist allowed event names in TypeScript so the server only inserts known events, track most events server-side during existing request handling, and use navigator.sendBeacon only for click events that exist purely in the browser.

_daily.dev surfaces practical approaches like this for developers weighing self-hosted analytics against third-party trackers._

### How do you send analytics events from the browser that survive page navigation?

Use navigator.sendBeacon to POST a JSON blob to an events endpoint, falling back to fetch with keepalive:true when sendBeacon is unavailable. The server validates the event name against a separate, smaller beacon-specific whitelist (distinct from the full server-side event whitelist), rejecting unknown names with a 400 and rate limiting with a 429.

_Developers building reliable client-side tracking can find similar implementation patterns on daily.dev._

### How do you compute a conversion funnel from raw event data in SQL?

Run two subqueries counting rows for each funnel step, such as COUNT(*) where name equals 'report_viewed' versus name equals 'checkout_completed' filtered by json_extract(meta,'$.product') = 'unlock', then divide one count by the other and multiply by 100 for a percentage. No dedicated analytics pipeline or third-party tool is required for basic funnel math.

_daily.dev helps developers compare lightweight SQL-based funnel analysis against heavier analytics platforms._

## Similar posts on daily.dev

- [What Every Dev Should Know About Tracking Product Data](https://daily.dev/posts/what-every-dev-should-know-about-tracking-product-data-epok7yxnx) · freeCodeCamp · 1 upvotes · 0 comments
- [Cloudflare Analytics Engine: store and query metrics](https://daily.dev/posts/cloudflare-analytics-engine-store-and-query-metrics-rynbqur3d) · Flavio Copes · 0 upvotes · 0 comments
- [Full-stack capabilities to power app analytics](https://daily.dev/posts/full-stack-capabilities-to-power-app-analytics-97k5pylpt) · Shopify Developer changelog · 0 upvotes · 0 comments
- [The Developer’s Way to Track Traffic: Self-Hosting Ackee or Plausible](https://daily.dev/posts/the-developer-s-way-to-track-traffic-self-hosting-ackee-or-plausible-89bg31qfb) · Ruby Flow · 0 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#sqlite](https://daily.dev/tags/sqlite)

[View this post on daily.dev](https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"First-party analytics with SQLite","url":"https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz"},"datePublished":"2026-07-19T07:40:19.109Z","dateModified":"2026-09-13T21:05:58.843Z","description":"A practical walkthrough of building first-party product analytics using a single SQLite events table on Cloudflare D1, replacing Google Analytics. Covers the...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/907c6c028f107fad7d0379f1571dde35?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/907c6c028f107fad7d0379f1571dde35?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"typescript,sqlite","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"First-party analytics with SQLite"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/first-party-analytics-with-sqlite-p5rk4jwpz#faq","mainEntity":[{"@type":"Question","name":"How can I track product analytics without using Google Analytics?","acceptedAnswer":{"@type":"Answer","text":"Build a single append-only SQLite events table with columns like id, name, src, anon_token, user_id, report_id, meta, and created_at, indexed on (name, created_at). Whitelist allowed event names in TypeScript so the server only inserts known events, track most events server-side during existing request handling, and use navigator.sendBeacon only for click events that exist purely in the browser. daily.dev surfaces practical approaches like this for developers weighing self-hosted analytics against third-party trackers."}},{"@type":"Question","name":"How do you send analytics events from the browser that survive page navigation?","acceptedAnswer":{"@type":"Answer","text":"Use navigator.sendBeacon to POST a JSON blob to an events endpoint, falling back to fetch with keepalive:true when sendBeacon is unavailable. The server validates the event name against a separate, smaller beacon-specific whitelist (distinct from the full server-side event whitelist), rejecting unknown names with a 400 and rate limiting with a 429. Developers building reliable client-side tracking can find similar implementation patterns on daily.dev."}},{"@type":"Question","name":"How do you compute a conversion funnel from raw event data in SQL?","acceptedAnswer":{"@type":"Answer","text":"Run two subqueries counting rows for each funnel step, such as COUNT(*) where name equals 'report_viewed' versus name equals 'checkout_completed' filtered by json_extract(meta,'$.product') = 'unlock', then divide one count by the other and multiply by 100 for a percentage. No dedicated analytics pipeline or third-party tool is required for basic funnel math. daily.dev helps developers compare lightweight SQL-based funnel analysis against heavier analytics platforms."}}]}
```

