Skip to main content

Install Umami Analytics Proxied By Caddy

utilities sysadmin

Umami analytics dashboard

Umami is a simplified web analytics dashboard that can display stats in real time. It’s much easier to navigate than Google Analytics or Matomo, although it lacks some of their advanced features.

Installation
#

Download and build
#

Follow the official install instructions. First, ensure you have a recent version of node installed. Umami recommends 16.13 or later.

node -v
sudo npm install -g yarn

Download from Github and run the yarn commands for a standard installation.

cd ~/git
git clone https://github.com/umami-software/umami.git
cd umami
yarn install
yarn build

Prepare the database
#

Create a MySQL or Postgresql database. I’m using MariaDB in place of MySQL..

create database umami;
grant all privileges on umami.* to 'umami'@'localhost' identified by '<PASSWORD>' with grant option;
flush privileges;
quit;

Set environment variables
#

Create an .env file in the installation directory – with database connection string and credentials. Optionally, you can disable telemetry.

DATABASE_URL=mysql://umami:<PASSWORD>@localhost:3306/umami
DISABLE_TELEMETRY=1

The documentation on environment variables also tells you how to rename/replace the default script.js, so that ad blockers are less likely to suppress it. For example, TRACKER_SCRIPT_NAME=custom. I’m using a different method to achieve the same goal, as I’ll explain in a moment.

Automate startup
#

Run yarn start to launch Umami. If it works, you can now browse to your website (https://localhost:3000, if running locally). This is a good time to login and change the admin password. While you’re there, add an initial site and copy the tracking code it generates.

Press Ctrl-C in your terminal to stop Umami. I followed the instructions to install the pm2 process manager:

sudo npm install pm2@latest -g
sudo pm2 update
pm2 start yarn --name umami -- start
pm2 startup

The pm2 startup command will output a line in your terminal like:

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u paul --hp /home/paul

Copy/paste this and press the Enter key to run it. It will create and enable a systemd script to start pm2 when your computer boots.

Finally, run pm2 save to remember the currently running app(s) – in this case, Umami – and restart them when pm2 launches.

Embed tracking code
#

Copy/paste the javascript shown in the site’s Tracking Code tab into the <head> section of your HTML template pages.

Umami displays javascript like this:

<script async src="https://your.caddy.subdomain/script.js" data-website-id="<WEBSITE_ID_GENERATED_BY_UMAMI>"></script>

I modified it to:

<script async src="https://your.caddy.subdomain/custom" data-website-id="<WEBSITE_ID_GENERATED_BY_UMAMI></script>

Webserver configuration
#

I’ll have the web server rewrite the /custom path so that it redirects to script.js. That way, I’m obscuring the tracker script without having to modify anything in the Umami filesystem.

I’m using Caddy web server as a reverse proxy to Umami. I’ll use its redir directive to perform the rewrite. My Caddyfile:

your.caddy.subdomain {
        reverse_proxy * localhost:3000
        redir /custom /script.js
        file_server
}

Resources
#

Related

Ansible Cmdb Host Data Collection
utilities sysadmin
ansible-cmdb makes it simple to collect summary data about all the machines on your home network.
Whisper CPP Voice Transcription
utilities sysadmin multimedia transcoding
What It Does # Want to transcribe some voice recordings quickly, without uploading them to a third-party service?
Ansible Installation For Daily Debian Package Updates
utilities system configuration sysadmin
Install # Performed on Debian 12 (bookworm)