A simple analytics implementation that collects and serves data from a static CDN, using web workers, WASM, range requests, and some other fun tricks.
Hosting SQLite databases on Github Pages | Discussion
- A "Snowplow-style Collector" is set up on a CDN (Bunny CDN in our case), to capture traffic data via requests to a transparent image (
o.png
), in our CDN's own log file format. - A job runs every 2 hours to download these log files, process them, and output the results in a SQLite database, which is stored statically & accessible to the public via range requests.
- Our simple frontend uses
sql.js
and sql.js-httpvfs to queryanalytics.sqlite3
(which is a static file hosted on a CDN).
Our entire Analytics implementation (collection - storage) is handled by static CDNs.
You can view a public demo here:
You can install on your own site, and then view your public analytics data on https://analytics.serv.rs/
<script src="https://analytics.serv.rs/a.js"></script>
Note: this is a toy project. It might be fun and handle a lot of data, but it isn't well reviewed and probably isn't very accurate or useful.
This project runs on Bunny CDN and Heroku or Herokuish (Dokku). You could probably tweak it to run anywhere though.
- Create a new bucket on Bunny CDN
- Upload
o.png
(included) to your bucket - Add a Pull Zone
- Copy the Full URL to
o.png
- Modify
public/a.js
line27
to point to the collector you just created (o.png
). - Optional: modify line 72 of
public/src/index.ts
to your own URL & runwebpack
to rebuild (from the/public
directory). - Update your Environment Variables based on the template
env
to include your Bunny CDN pull zone ID and API key. This is required fornpm run build
to run, and parse your log files. - Deploy the project
- Include the script
a.js
on your website somewhere (it's already included in the project you deploy) - Optional: set up a cron job to rebuild (
npm run build
) the site every few hours, or day. This will fetch logs and update.
Go to the project you deployed. Enter the hostname of the website you wish to view analytics for, if you didn't complete step 2 above.
That's it!
- Setup a GitHub Action to run the batch processing job (instead of doing it on a server) for a "more static, more serverless" experience.
- Consider implementing High Water Marks for larger projects