Skip to content

Web analytics project to track the time visitors spend on the website. IMPORTANT! Project's development is moved to from my Github to GDSC BME. Check link below.

License

Notifications You must be signed in to change notification settings

VMois/flarelytics

Repository files navigation

Flarelytics

TypeScript JavaScript License

Web analytics project to track the time visitors spend on the website.

At this moment, the project is under active development and is not ready for production use.

Built on top of Cloudflare Workers and MongoDB (undergoing transition to PlanetScale/MySQL). Currently, supports tracking for a single domain only.

Mainteined by Google Developer Student Club at Budapest University of Technology and Economics.

Project lead: @VMois.

Why this project?

Being able to tell if people spend time reading your content (e.g. blog article) is crucial and makes you feel great too. Unfortunately, the popular web analytics services are violating visitors' privacy (e.g., Google Analytics is illegal in some EU states) or do not have a metric that checks how long people spend reading (e.g., Plausible for single page visits).

In addition, due to the increased ad/tracker blockers, even privacy-friendly web analytics tools might be blocked. One of the solutions is to deploy your custom web analytics solution to reduce the number of blocks. This article dives into pros and cons of self-hosted web analytics.

The Flarelytics project was born in response to the need for a self-deployable, privacy-friendly web analytics service to collect the time readers spend on each webpage.

How it works?

The project consists of two parts:

  • Browser script - a JS script that needs to be embedded to the website; it sends events when visitors open and close the website.
  • Backend - a TypeScript code that runs on Cloudflare Worker with a simple HTTP API.

This article explains how the browser script works.

In short, every time a visitor opens a webpage (that has Flarelytics tracking script), the browser script generates a unique UUID and sends a request to the backend called event. The backend stores the event in the database. The browser script sends another event to the backend when the visitor closes the webpage. When the user of Flarelytics (website owner) visits the dashboard, the backend will calculate the time spent on each webpage by the visitor.

Contributing

We welcome contributions from the community to help improve and expand this project. Before you start, please take a moment to review the following guidelines to ensure a smooth and productive collaboration.

How to contribute

  1. Select an Issue: You can find open issues (tasks) that need to be done, if you are interested, you can ask to be assigned to this issue and start working on it. In addition to the open issues, we also have a project board (that also contains the open issues) where you can see the progress of the project.

  2. Fork the Repository: follow Github guide on setting up your fork.

  3. Set Up the Development Environment: Follow the instructions in the "Development" section of the README to set up your development environment, including installing the necessary dependencies.

  4. Follow Github Flow to Add Code Changes: more details in Github guide.

Development

In this section, you will find instructions on how to set up the development environment.

Prerequisites

Do the steps below to set up the development environment:

  1. Create free Cloudflare account.
  2. Create free PlanetScale account.
  3. Install Node.js, nvm (optional; for Linux, MacOS and Windows WSL), npm or pnpm.
  4. Run npm install (or equivalent) to install necessary packages.

Environment variables

For local development, secrets are stored in .dev.vars file and non-sensitive variables can be defined in wrangler.toml file.

For production, secrets need to be defined in Cloudflare Workers. Either with UI, or using wrangler tool.

Running locally

To run the project locally, run npm run dev (or equivalent) command. It will start a local Workers server.

Where the project name comes from?

The project name was created from simple concatenation CloudFLARE + AnaLYTICS = Flarelytics.

About

Web analytics project to track the time visitors spend on the website. IMPORTANT! Project's development is moved to from my Github to GDSC BME. Check link below.

Topics

Resources

License

Stars

Watchers

Forks