Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/statico/femtostats
📊🌍 Super small, light, privacy-focused, self-hostable web statistics provider
https://github.com/statico/femtostats
analytics google-analytics pageviews statistics stats tracking tracking-pixels webstats
Last synced: 4 days ago
JSON representation
📊🌍 Super small, light, privacy-focused, self-hostable web statistics provider
- Host: GitHub
- URL: https://github.com/statico/femtostats
- Owner: statico
- License: gpl-3.0
- Created: 2022-09-17T18:57:45.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T23:57:19.000Z (5 months ago)
- Last Synced: 2024-06-17T00:41:55.866Z (5 months ago)
- Topics: analytics, google-analytics, pageviews, statistics, stats, tracking, tracking-pixels, webstats
- Language: TypeScript
- Homepage: https://github.com/statico/femtostats
- Size: 419 KB
- Stars: 18
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# femtostats
Femtostats is a lightweight, tiny, privacy-focused web statistics provider with no RDBMS requirement.
[![build status](https://img.shields.io/github/actions/workflow/status/statico/femtostats/build.yml?branch=main&style=flat-square)](https://ghcr.io/statico/femtostats)
## Why?
- Self-hostable
- Easy setup with a single `` tag
- Simple pageview and session tracking
- Arbitrary client-side event tracking
- Realtime visitor count
- No external database requirement (uses SQLite)
- Not blocked by common ad blockers and browsers
- No storage of personally-identifable data (PII)
- Collection of client-side performance stats and screen width
- Geographic tracking with a free Maxmind account signup
- Optional cookieless operation to abide by privacy laws## Why not use ........?
| What | Why not? |
| ----------------------------- | ------------------------------------------------------------------------------ |
| Google Analytics | Blocked by ad blockers and feeds your site's data into the Google data machine |
| CloudFlare Web Analytics | Blocked by ad blockers |
| Plausible | Self-hosting requires both additional Postgres and Clickhouse databases |
| Fathom Lite | The project is in maintenance-only mode and requires a Fathom account |
| Server logs | Doesn't record client information or sessions |
| CloudFront logs + S3 + Athena | Logs only get dumped once per day and querying requires writing raw SQL |## Getting Started
1. Host the image `ghcr.io/statico/femtostats` wherever you want.
- Check out the `docker-compose.yml` file in this repo as an example.
- See below instructions on creating a Maxmind account to resolve geographic location at the country level.
- Set a `PASSWORD` env var to protect your dashboard behind a password (the username is `admin`).
- Set a `DATA_DIR` env var to store the SQLite database and Maxmind database. (Default is `/tmp`.)
1. Run `pnpm knex:migrate` to initialize the database.
1. Include the tag `<script defer src="https://your-femtostats.com/data.js">` on the pages you want to track.
1. For custom event tracking, call `window.femtostats('event name')`### Enabling Country Resolution
To record which country the user has originated from, you need a geoip database. Femtostats will automatically download a free one from Maxmind and refresh it once a week if you do the following:
1. Go to https://www.maxmind.com/ and register for a free account
1. Under "Manage License Keys", get a license key
1. Under "Download Files", scroll to the "GeoLite2 Country" row and click "Get Permalinks". Get the database URL (it will look like `https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=YOUR_LICENSE_KEY&suffix=tar.gz`) and replace `YOUR_LICENSE_KEY` with your license key.
1. Set this URL as an environment variable `MAXMIND_GEOLITE2_COUNTRY_URL`### Disabling Cookies
By default, Femtostats stores a simple cookie on the client to count unique users and user sessions. You can disable the use of cookies entirely by adding `data-cookies="false"` to the `` tag you embed on your site. Sessions will still show in the dashboard, but without cookies, the definition of a session changes from "a user's browser session" to "a single page view."
### Other notes
The script tag instructions used to reference `script.js`, but uBlock appears to be [blocking that](https://github.com/uBlockOrigin/uAssets/blob/927dec7c9c60b6c1701d69ea9f8e5923644dd9dc/filters/privacy.txt#L376).
## Development
Requires Node.js 16+ and [pnpm](https://pnpm.io). Run `pnpm` and `pnpm install`.
The default database location is `/tmp/stats.db`. Run `pnpm knex:seed` to populate the database with some sample data.
This project uses [Next.js](https://nextjs.org/), [React](https://reactjs.org/), [SWR](https://swr.vercel.app/), [Recoil](https://recoiljs.org/), [Chakra UI](https://chakra-ui.com/), and [Chart.js](https://www.chartjs.org/).
## Future Ideas
- Use the [better-sqlite3](https://www.npmjs.com/package/better-sqlite3) driver
- Support other databases, maybe, I dunno
- Support UTM campaigns