Howto

Installation

  1. Rename .env.example to .env and update config vars
  2. npm i to install node modules
  3. npx prisma migrate deploy to apply db schema
  4. npm start to start the application

How to access API

  1. API_KEY environment var should be set in order to access API
  2. Get report for site GET /api?site=$siteId&apiKey=API_KEY
  3. List all sites GET /api/sites?apiKey=API_KEY

Fly.io deployment

  1. Download the source code
  2. Register an account at Fly.io, download the flyctl and sign in
  3. Install dependencies: Run npm i
  4. Initiate setup: Execute fly launch
  5. Add Environment Variables USERS and API_KEY. This can be done either via the flyctl or the web UI
    • Command: fly secrets set USERS=user:pass321,user2:pass123 API_KEY=MyS3cret
    • DATABASE_URL is automaticlly set by Fly.io so you don't have to set it
  6. Deploy the application by running fly deploy
  7. Now you will get assigned a subdomain from fly.io, or you can assign your own domain through fly.io UI. Whichever domain you choose, set a new environment variable DOMAIN:
    • Command: fly secrets set DOMAIN=https://yourdomain.com

Render.com deployment

  1. Download the source code.
  2. Register an account at render.com
  3. Create a PostgreSQL database on Render.com
    • Choose PostgreSQL version 15
    • While the PostgreSQL service is setting up, you can set up the Web Service
  4. Add your analytics code to your private GitHub or GitLab repository. This is required before setting up the Web Service
  5. Create a Web Service:
    • Choose "Build and deploy from a Git repository"
    • Connect to your GitHub or GitLab repository and select the repo where your analytics code is located
    • Select Runtime: Docker
    • Add Environment Variables: DATABASE_URL, USERS, API_KEY
    • Retrieve the "Internal Database URL" from the PostgreSQL service set up earlier. Set this as the DATABASE_URL environment variable
    • Click "Create Web Service"
  6. Render will now deploy your analytics. The app should be up and running within 2-3 minutes
  7. Inside Render Dashboard, you will find the assigned domain. Now add that domain as the DOMAIN environment variable and restart the service.