banner
幻梦晓寒

幻梦晓寒HACK-FOX

醉后不知天在水,满船清梦压星河
x
github
bilibili
vrchat

Add a statistics system to your blog with umami!

This article was rewritten on 2024-7-5

Preface#

I have been thinking about abandoning Google Analytics for a long time, mainly 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 used a PostgreSQL database hosted by Supabase. The specific choice depends on you, you can refer to their documentation.

https://umami.is/docs/

Deployment#

  1. Fork the Umami repository and then import it into Vercel.

  2. 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 the domain of your database connection, for example, postgres://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 the settings.

Create a new website with any name and enter your website domain in the domain field.

For Hexo#

Then insert its JavaScript snippet into the inject bottom section, and three consecutive commands for Hexo, then you can use it.

You can also create a shared page 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 details: 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


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.