How to deploy Plausible Analytics
Why Plausible Analytics
At first, I just used Google Analytics for my blog. But soon I found its weakness: the record can not be obtained if visitor have no access to google service. Then, I changed it with Baidu Analysis, a Chinese friendly statistics tool. However, it alse has two drawback. One is that it would be blocked if user including myself install AD block extension. The other one is it can only storage your data for 1 year, which is user-unfriendly. So I decided to build my own analytics tool.
This journey is not a walk in the park. In the beginning, I just tried to use Umami. I failed in installation both from source and docker and raised an issue. This was quite a time-taking work and finally I quit and choose another similar open source project: as you can see–Plausible Analytics. I think this name is very interesting, which means the data of your blog or your website is plausible.
How to deploy
Clone the project
1
2git clone https://github.com/plausible/hosting
cd hostinggenerate your own hash salt(secret key).
1
openssl rand -base64 64 | tr -d '\n' ; echo
Edit plausible-conf.env
1
vim plausible-conf.env
1
2
3BASE_URL=http://your_domain_for_this
SECRET_KEY_BASE="the result from openssl rand -base64 64 | tr -d '\n' ; echo"
DISABLE_REGISTRATION=invite_only # this set is to disable registrationCompose the docker
1
docker-compose up -d
Set nginx reverse proxy and then apply and install SSL certificate.
1
2sudo certbot certonly --nginx -d your_domain
vim /etc/nginx/sites-available/00-default-ssl.conf1
2
3
4
5
6
7
8
9
10
11
12
13server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/your_domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your_domain/privkey.pem;
server_name your_domain;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:8000/;
}
}Notice that it is more complicated than that before we set because we want to get user’s real ip address so that the user country map can be generated.
PS: The initiation of web is simple so I ignored them there.
Use in hexo
1
2
3#chan the work path to your hexo config
cd blog
vim _config.yml1
2
3
4
5theme_config:
plausible:
enable: true
script_url: https://your_plausible_domain/js/script.js
site_domain: doublefire.chen.bbb.enterprises