Build a Clean and Stylish Website Analytics (Analysis) with Docker

Publish: 2022-05-16 | Modify: 2022-05-16

On May 10, 2022, U-Web (CNZZ/Umeng) announced the closure of services for all unpaid accounts. You can refer to the announcement here. There are many alternative products available, such as Baidu Analytics and 51la in China, and Google Analytics internationally. If you're not satisfied with any of these options, you can also consider self-hosted website analytics solutions like Umami, Plausible, or Matomo. Today, let's talk about Umami as one of the self-hosted solutions.

Umami

About Umami

According to the official website:

Umami is a simple, easy-to-use, self-hosted web analytics solution. The goal is to provide you with a more friendly, privacy-focused alternative to Google Analytics, as well as a free and open-source alternative to paid solutions. Umami only collects the metrics you care about and presents them on a single page.

Setting up Umami with Docker

Prerequisites:

My Setup:

Since everyone's environment may be different, this article may not apply to everyone, but it can serve as a reference. I already have MySQL installed on my server, so when deploying with Docker, I didn't need to install MySQL separately. I simply used the existing MySQL installation.

Importing the Database:

  1. You need to create a MySQL database for Umami to use.
  2. Then, download the official initial data and import it into the database. You can find the initial SQL statement download link here.

I have already created a database named umami and imported the initial data schema.mysql.sql.

Importing Database

Deploying Umami with docker-compose

If you haven't installed docker-compose yet, please refer to the official documentation for installation: Install docker-compose

Using docker-compose for deployment makes it easier for maintenance and management. You need to create a docker-compose.yaml file with the following content:

---
version: '3'
services:
  umami:
    image: ghcr.io/mikecao/umami:mysql-latest
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: mysql://username:[email protected]:3306/umami
      DATABASE_TYPE: mysql
      HASH_SALT: replace-me-with-a-random-string
    restart: always
    network_mode: "host"

The parameters in the file should be modified according to your own situation:

  • username: MySQL username
  • password: MySQL password
  • 127.0.0.1:3306: MySQL connection address and port
  • umami: MySQL database name

Here, I used the HOST network, network_mode: "host", because my MySQL is set up on the host machine. If you don't specify the HOST network, it won't be able to communicate with Docker.

To start, simply run the command docker-compose up -d.

Accessing Umami

After the setup, Umami will be available on port 3000. You can access it using http://IP:3000. The default username is admin and the password is umami.

Umami Login

The default interface is in English. After logging in, you can click the "globe" icon in the top right corner to switch to Chinese.

Change Language

Nginx Reverse Proxy

Accessing Umami through IP and port is only suitable for temporary testing and not recommended for production. You can use Nginx reverse proxy to enable domain access.

Here is an example Nginx reverse proxy configuration. Please modify it according to your actual situation:

server {
    listen 80;
    listen 443 ssl http2;
    server_name domain.com;
    index index.php index.html index.htm default.php default.htm default.html;

    # SSL configuration, please don't delete or modify the following line
    # error_page 404/404.html;
    # Redirect HTTP to HTTPS
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #SSL-END

    # Other configuration...

    location ^~ / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        # Additional proxy settings...
    }

    # Other configuration...
}

If you are using the Baota control panel, you can also use its reverse proxy feature. Simply follow the instructions in the screenshot.

Baota Reverse Proxy

Umami User Experience

Umami has a simple interface with limited options, making it easy to get started. In terms of functionality, it is sufficient but not as feature-rich as Baidu Analytics or Google Analytics. It still has a long way to go to replace these commercial analytics solutions.

Umami Dashboard

Conclusion

  1. Umami requires MySQL or PostgreSQL for installation.
  2. Before installing, you need to import the initial data.
  3. The default username is admin, and the password is umami.
  4. Umami has a clean and user-friendly interface, with support for multiple languages.
  5. While Umami's functionality is simple, it lacks the depth of data and features compared to Baidu Analytics and Google Analytics. It still has a long way to go to fully replace these commercial analytics solutions.


Comments