Umami: Simpler self-hosted website statistics service

Original link: https://scottyeung.top/2023/umami/

Previously, blogs used Google Analytics to provide website statistics services, counting the visits of each page in the blog. Available is available, but Google Analytics provides so many statistics that it is confusing to know what to look at. In addition, Google’s services will always have accessibility problems. Therefore, after seeing the article introducing other bloggers introducing Umami , I also plan to build my own website statistics service and switch.

Umami is a simple, fast, privacy-focused alternative to Google Analytics.

Umami focuses on privacy. After all, data such as access data should not fall into the hands of large companies. Umami supports multiple deployment methods, such as Docker. But for cloud computing enthusiasts like me, of course, they all use cloud services. The Umami service itself can be deployed on Vercel, and it can be directly accessed by binding a domain name. Umami supports MySQL and Postgresql databases, both of which can find corresponding serverless providers. Here I choose TiDB Cloud from PingCap, which can provide a maximum capacity of 5G per cluster and a MySQL database with 50 million visits per month.

The results of the final deployment are as follows.

202306141051580.png

build process

  1. After logging in to TiDB Cloud, create a Serverless database cluster

  2. On the overview page of the cluster, click connect to obtain related content on establishing a database link. Take the connection method of MySQL CLI as an example, including

    • username -u
    • host -h
    • Port-P
    • password -p
  3. According to the obtained relevant information, splicing out the connection URL of MySQL

    • mysql://<username>:<password>@<host>:<port>/<database_name>?pool_timeout=60&sslaccept=accept_invalid_certs
    • Need to create a database in advance and specify the database
    • Because TiDB Cloud requires TLS by default, you must add the parameter sslaccept=accept_invalid_certs , otherwise you will not be able to connect (this is a hidden pit)
  4. GitHub Fork Umami project, and deploy it to Vercel, fill in the environment variable DATABASE_URL when deploying, the value is the connection URL above

  5. After deployment, bind your own domain name to Vercel. Due to DNS pollution, the domain name provided by Vercel cannot be accessed normally most of the time. You need your own domain name to be accessed more smoothly.

  6. After the deployment is successful, access the website through the bound domain name. The default account username and password are admin and umami. After entering, you can modify the password, add websites, and add users

  7. Add a website on the setting page, fill in the relevant information, and Umami will assign an ID and the affected tracking code to the website that needs to be counted. Just put this tracking code in the head tag of the webpage, you can start collecting statistical data, and see the corresponding statistical results in the dashboard.

    1. Take the hugo I use as an example, find the generated template related to the head tag in the html template of the theme, and then put the tracking code in it. In order to increase the configurability, the id in the tracking code can also be extracted and turned into a variable, which can be read from the configuration.
     1 2 3 4 5 6
     < script async src = "https:///script.js" data-website-id = "" ></ script >
     1 2 3
     enableUmami = true umamiTrackingID = "your_id" umamiHost = "your_umami_website"

This article is transferred from: https://scottyeung.top/2023/umami/
This site is only for collection, and the copyright belongs to the original author.