Giter Club home page Giter Club logo

femtostats's Introduction

femtostats

Femtostats is a lightweight, tiny, privacy-focused web statistics provider with no RDBMS requirement.

build status

CleanShot 2022-09-25 at 12 43 28@2x

Why?

  • Self-hostable
  • Easy setup with a single <script> 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.)
  2. Run pnpm knex migrate:latest to initialize the database.
  3. Include the tag <script defer src="https://your-femtostats.com/data.js"></script> on the pages you want to track.
  4. 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
  2. Under "Manage License Keys", get a license key
  3. 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.
  4. 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 <script> 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.

Development

Requires Node.js 16+ and pnpm. Run pnpm and pnpm install.

The default database location is /tmp/stats.db. Run pnpm exec knex seed:run to populate the database with some sample data.

This project uses Next.js, React, SWR, Recoil, Chakra UI, and Chart.js.

Future Ideas

  • Use the better-sqlite3 driver
  • Support other databases, maybe, I dunno
  • Support UTM campaigns

femtostats's People

Contributors

statico avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.