A minimal analytics tool to self-host.
Short demo video
demo.mov
This is heavily inspired by the piratepx.
Get one from Upstash, Render or Redis.
Get one from Supabase, Render or CockroachDB.
Important
You should use a transaction pooler connection.
Get one from MongoDB.
Get one from Turso or use a local file with file:./path/to/file.db as the connection url.
Important
It uses libsql to connect to the database.
For some variables the VITE_ prefix is required, because the app is built using Vite.
| Key | Value | Default |
|---|---|---|
ANALOG_TOKEN |
Protects requests. Leave empty if no protection is required. | |
ANALOG_DATABASE_PROVIDER |
Defines the kind of database to use. Possible values: redis, postgresql, mongodb, sqlite. |
|
ANALOG_REDIS_URL |
Redis connection url. | |
ANALOG_POSTGRESQL_URL |
PostgreSQL connection url. | |
ANALOG_MONGODB_URL |
MongoDB connection url. | |
ANALOG_SQLITE_URL |
SQLite connection url. Add an authtoken query parametre if you need to use the authToken to initilise the connection. |
|
ANALOG_DATABASE_REQUEST_ITEM_COUNT |
The item count the API server requests from the database. | 10 |
ANALOG_PROTECT_POST |
Set to true if ANALOG_TOKEN is present and you want to protect the POST requests. |
false |
ANALOG_STATIC_SERVER |
Set to true to make the Node.js server also serve static content. In this case the contents of ./src/services/server/dist folder are used. |
false |
ANALOG_PORT_SERVER |
The port you want the Node.js server to listen on. | |
VITE_ANALOG_PAGE_TITLE |
Page title. | |
VITE_ANALOG_TIME_RANGE |
Time range to show data for. Minimum is 10, maximum is 30. |
30 |
VITE_ANALOG_API_GET_REQUEST_QUEUE |
Defines if the request to the API is done in a sequence, rather than fetching all the data in one go. | true |
VITE_ANALOG_API_GET_REQUEST_CLEAN_UP |
Defines if the data clean up occurs along with the GET request. |
true |
Clone this repository.
Create .env.local with your settings.
Then run:
npm install
npm run devThis launches the frontend app and the node server.
Create a project with a copy of this repository. The settings are in the netlify.toml.
Configuration to schedule the clean up function to run every day:
[functions."cleanUp"]
schedule = "@daily"Important
Scheduling may not work, because of the runtime limitations.
Create a project with a copy of this repository. The settings are in the vercel.json.
Configuration to schedule the clean up function to run every day:
"crons": [
{
"path": "/api/cleanUp",
"schedule": "0 0 * * *"
}
]Important
Scheduling may not work, because of the runtime limitations.
Use the Dockerfile to build and run the app in a Docker container, based on your environment:
docker build \
--build-arg VITE_ANALOG_API_GET_REQUEST_QUEUE=false \
--build-arg VITE_ANALOG_API_GET_REQUEST_CLEAN_UP=false \
-t analog-analytics .
docker run -d \
-p 80:80 \ # For local development
-e ANALOG_STATIC_SERVER=true \
-e ANALOG_PORT_SERVER= \ # 80 for HTTP or 443 for HTTPS
-e ANALOG_DATABASE_PROVIDER= \
-e ANALOG_REDIS_URL= \
--name analog-analytics \
analog-analyticsIf you have ANALOG_TOKEN environment variable present, then you need the token query parametre in the url. For example, hostname/?token=ANALOG_TOKEN.
/api/events
Authorization?: Bacis *— if the environment variableANALOG_TOKENis present, the value must be equal to it, prefixed byBasic
cursor?: string— page pointer to query the database; if omitted, the API fetches all the data in one goclean-up?: boolean— if the parametre is present, the clean up occurs along with fetching the data
{
data: {
[event: string]: number[];
};
nextCursor: string;
}{
[event: string]: number[];
}Authorization?: Basic *— if the environment variablesANALOG_PROTECT_POSTandANALOG_TOKENare present, the value must be equal toANALOG_TOKEN, prefixed byBasic
event: string— contains the event name
OK