https://github.com/zgreen/dumb-analytics
A very simple, open-by-default analytics server, backed by redis.
https://github.com/zgreen/dumb-analytics
Last synced: 11 months ago
JSON representation
A very simple, open-by-default analytics server, backed by redis.
- Host: GitHub
- URL: https://github.com/zgreen/dumb-analytics
- Owner: zgreen
- Created: 2018-05-12T01:55:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T18:15:58.000Z (over 3 years ago)
- Last Synced: 2025-06-06T03:40:51.359Z (12 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dumb-analytics
This is a simple analytics server, backed by redis. You might use it if:
* you want your analytics to be very simple
* you want your analytics to be open
* you distrust, or are wary of, Google's approach to user privacy and data collection
## Install
`npm install dumb-analytics`
## Requirements
This package requires a redis server to work. The following environment variables must be loaded:
* `ALLOWED_ORIGIN` (this should be the only origin that is allowed to update analytics on your site, e.g. `https://yoursite.cool`)
* `REDIS_USER`
* `REDIS_PASSWORD`
* `REDIS_URL`
* `REDIS_PORT`
## Usage
### The server
This example loads environment variables using [dotenv](https://www.npmjs.com/package/dotenv).
```js
// server.js
require('dotenv').config()
const server = require('dumb-analytics')
server.listen(3000, () => console.log('Server listening...'))
```
### Updating analytics from the client
```js
// client.js
fetch(`https://myanalyticssite.cool?url=${window.location.pathname}`)
```
### View current analytics
`dumb-analytics` serves analytics data from the homepage. This is publicly viewable.
The shape of the data will be:
```json
{
"err": null,
"byDate": [{ "total": 1, "date": "20180511", "url": "/" }],
"byUrl": [{ "url": "/", "total": 1 }],
"total": 1
}
```
* `err` is an error, if any has occured.
* `byDate` is an array of objects grouped by URL and date.
* `byURL` is an array of objects with the overall visit total per URL.
* `total` is the total number of visits to the site.