This article was rewritten on July 5, 2024.
Preface#
I have been thinking about abandoning Google Analytics for a long time because it has too many features that I don't need for my small blog. I heard about self-hosted analytics called Umami earlier this year, but the v1 version had some issues and couldn't connect to the database, so I gave up. Recently, I found out that Umami has released v2, so I tried again and succeeded. Now I will share my process below.
Preparation#
First of all, Umami uses the Next.js framework, so you can choose to deploy it on Vercel. You also need a database to store the analytics data, which supports MySQL or PostgreSQL. I am using a PostgreSQL database hosted by Supabase. The specific choice depends on you, and you can refer to their documentation.
Deployment#
-
Fork the Umami repository and then import it into Vercel.
-
Usually, Vercel will automatically select the framework and build command for you, so you don't need to worry about these. Then, in the environment variable options, create a new variable named
DATABASE_URL
and fill in the value with your database connection domain, such aspostgres://postgres:[YOUR-PASSWORD]@host:6543/postgres
.
For Supabase Database#
If you are using a Supabase hosted database, you need to go to the db/postgresql/schema.prisma
path in the repository and modify the parameters by adding directUrl = env("DIRECT_DATABASE_URL")
.
Then, in the Vercel deployment, in addition to adding DATABASE_URL
, you also need to add an environment variable named DIRECT_DATABASE_URL
with the value of the connection string for using connection pooling.
In simple terms, fill in the connection string for the DATABASE_URL with the connection port 6543, and fill in the connection string for the DIRECT_DATABASE_URL with the connection port 5432.
Usage#
After successful deployment, log in to the management panel and go to Settings.
Create a new website with any name and enter your website domain in the Domain field.
For Hexo#
Then, insert the JavaScript snippet into the inject bottom section, and three consecutive commands for Hexo, and you can start using it.
You can also create a shared page to use as a visitor analytics page for your blog. The visitor statistics on this site are implemented using this feature.
For Mix-Space#
Someone has already written about it, so I won't go into detail: https://blog.nekorua.com/posts/mx-space/118.html
This article is synchronized and updated to xLog by Mix Space.
The original link is https://blog.xiaohan-kaka.me/posts/default/umami