Skip to content

goatcounter

Privacy-friendly analytics for your sites

Goatcounter is an open source web analytics platform available as a free, donation-supported hosted service or self-hosted app.

It aims to offer easy to use and meaningful privacy-friendly web analytics as an alternative to Google Analytics or Matomo. This guide installs the application at ~/goatcounter/. The service is named “goatcounter”, uses port 8080 internally and is exposed at stats.example.com. It logs to the systemd journal. Supports both SQLite and PostgreSQL.


Note

For this guide you should be familiar with the basic concepts of:

Installation

Download and install the linux-amd64.gz variant and extract it to ~/goatcounter:

[isabell@moondust ~]$ mkdir -p ~/goatcounter
[isabell@moondust ~]$ cd ~/goatcounter
[isabell@moondust ~]$ wget -O goatcounter.gz https://github.com/arp242/goatcounter/releases/download/v2.7.0/goatcounter-v2.7.0-linux-amd64.gzz
[isabell@moondust ~]$ gzip -d goatcounter.gz
[isabell@moondust ~]$ chmod +x goatcounter/goatcounter
[isabell@moondust ~]$ rm goatcounter.gz

Create SQlite database:

[isabell@moondust ~]$ mkdir -p ~/goatcounter/db

Create a systemd service unit at ~/.config/systemd/user/goatcounter.service with the following content:

[Unit]
Description=GoatCounter Web Analytics
After=network.target

[Service]
Type=simple
WorkingDirectory=%h/goatcounter
ExecStart=%h/goatcounter/goatcounter serve -listen :8080 -tls http -db sqlite+%h/goatcounter/db/goatcounter.sqlite3
Restart=always
RestartSec=5

[Install]
WantedBy=default.target

Add a domain and create a web backend to make the service available:

[isabell@moondust ~]$ uberspace web domain add stats.example.com
[isabell@moondust ~]$ uberspace web backend add stats.example.com PORT 8080

Do not forget to add the DNS entries!


Reload systemd, enable the service for automatic startup, and start it now. This creates the authentication database needed by the user and permission commands below:

[isabell@moondust ~]$ systemctl --user daemon-reload
[isabell@moondust ~]$ systemctl --user enable --now goatcounter
[isabell@moondust ~]$ systemctl --user status goatcounter

Web Interface

Goatcounter provides a web interface which displays analytics.

The web interface is available at stats.example.com.

Backup

Stop Goatcounter while backing up the entire data folder ~/goatcounter/db so that its SQLite databases are not changing during the backup. Restart it afterwards:

[isabell@moondust ~]$ systemctl --user stop goatcounter
[isabell@moondust ~]$ tar -cf - ~/goatcounter/db | zstd - > goatcounter.tar.zstd
[isabell@moondust ~]$ systemctl --user start goatcounter

Updates

Note

Check the release feed regularly for new versions.

To update Goatcounter, download the new version and replace the executable. Replace 2.7.0 in the installation commands with the version you want to install.

[isabell@moondust ~]$ cd ~/goatcounter
[isabell@moondust goatcounter]$ wget -O goatcounter.gz https://github.com/arp242/goatcounter/releases/download/v2.7.0/goatcounter-v2.7.0-linux-amd64.gz
[isabell@moondust goatcounter]$ gzip -dc goatcounter.gz > goatcounter.new
[isabell@moondust goatcounter]$ chmod +x goatcounter.new
[isabell@moondust goatcounter]$ mv goatcounter.new goatcounter
[isabell@moondust goatcounter]$ rm goatcounter.gz

Finally, restart the service and check its status:

[isabell@moondust goatcounter]$ systemctl --user restart goatcounter
[isabell@moondust goatcounter]$ systemctl --user status goatcounter