Monocle is a web analytics tool that allows you to track user interactions on your website.
Monocle is split into multiple packages
@monocle/api handles requests from the different clients and stores data in the database.
@monocle/ui allows you to view analytics data.
@monocle/browser focuses on tracking interactions and collecting data that may occur in a browser.
@monocle/node focuses on tracking interactions and collecting data that may occur in a node environment.
@monocle/react built on top of @monocle/browser for react support.
To run the local demo, run the following commands:
docker compose -f docker-compose.demo.yml up -d
docker compose -f docker-compose.demo.yml exec mongo mongosh --eval 'rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "mongo:27017" }] })'
docker compose -f docker-compose.demo.yml exec monocle-api pnpm prisma db seedGo to http://localhost:8080 to view the blop example app.
Go to http://localhost:8081 to access the analytics back-office.
You can use the following credentials to login to the back-office:
email: blog@demo.com
password: password
npm install @ekezoh/monocle.apiyarn add @ekezoh/monocle.apipnpm add @ekezoh/monocle.apiUse the createMonocleServer function to create an express server that you can extend.
import { createMonocleServer } from "@ekezoh/monocle.api";
const server = createMonocleServer({
corsOrigin: "https://example.com",
});
server.listen(3000);Make sure to set the following environment variables:
MONOCLE_DATABASE_URL is the url of the database to use. (no default)
MONOCLE_CORS_ORIGIN is the origin to allow cors from. (default: *)
JWT_SECRET is the secret to use for signing jwt tokens. (no default)
docker run -p 3000:3000 --env-file .env -d @ekezoh/monocle.api- Node.js >= 18.16.1
- pnpm
- Docker
- Docker Compose
At the root of the repository, run the following command to install all dependencies:
pnpm installCopy all .env.example files to .env files.
# Linux based systems
find . -type f -name ".env.example" -exec sh -c 'cp "$1" "${1%.example}"' _ {} \;To start the development database, run the following command:
docker compose up -d
docker compose exec mongo mongosh --eval 'rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27017" }] })'To seed the database, run the following commands in the packages/api directory:
pnpm exec prisma generate
pnpm exec prisma db seedTo view the data, you can use prisma studio.
pnpm exec prisma studioOr use mongo-express running on port 8888.
api and ui has a dev script that you can run to start the development server.
pnpm devOther packages can be built using nx
pnpm exec nx build <package>