banner
幻梦晓寒

幻梦晓寒HACK-FOX

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

用 umami 給你的部落格添加一個統計系統吧!

This article was rewritten on 2024-7-5

前言#

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.

准备#

First of all, umami uses the nextjs 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 is up to you. You can refer to their documentation.

https://umami.is/docs/

部署#

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

  2. Generally, 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 domain name of your database connection as the variable value. 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 addition to adding DATABASE_URL in the Vercel deployment, 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 port 6543 in DATABASE_URL, and fill in the connection string for the port 5432 in DIRECT_DATABASE_URL.

使用#

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 umami JavaScript snippet into the inject bottom section, and three steps 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 repeat it: https://blog.nekorua.com/posts/mx-space/118.html

This article is synchronized updated to xLog by Mix Space
The original link is https://blog.xiaohan-kaka.me/posts/default/umami


載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。