An open source analytics tool for flutter -- Aptabase

When I develop app using flutter, I tried to use plausible as analytics tool. However, I found that plausible is more suitable for website, did not work well cross platforms. So I decided to use another anaylytics tool. And I found aptabase finally, which works perfectly in flutter.

How to install aptabase

Docker configuration

Log into your server as root.

1
2
3
4
mkdir aptabase
git clone https://github.com/aptabase/self-hosting aptabase
cd aptabase
vim docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
services:
# ClickHouse still lives in Docker
aptabase_events_db:
container_name: aptabase_events_db
image: clickhouse/clickhouse-server:23.8.4.69-alpine
restart: always
volumes:
- events-db-data:/var/lib/clickhouse
environment:
CLICKHOUSE_USER: aptabase
CLICKHOUSE_PASSWORD: your_password
ulimits:
nofile:
soft: 262144
hard: 262144

aptabase:
container_name: aptabase_app
image: ghcr.io/aptabase/aptabase:main
restart: always
depends_on:
- aptabase_events_db
ports:
- "8000:8080"
# Tell the container where to find Postgres on the **host**
environment:
BASE_URL: https://aptabase.example.com
AUTH_SECRET: c4rI4x8kz5DgKJ1is5Eiu9bNncSQ6ROD # get a strong secret from https://randomkeygen.com/
DATABASE_URL: Server=host.docker.internal;Port=5432;User Id=aptabase;Password=your_password;Database=aptabase
CLICKHOUSE_URL: Host=aptabase_events_db;Port=8123;Username=aptabase;Password=your_password
# ── NEW: SMTP settings ──────────────────────────────
SMTP_HOST: mail.example.com
SMTP_PORT: "465" # 587 (STARTTLS) or 465 (implicit TLS)
SMTP_USERNAME: aptabase@example.com
SMTP_PASSWORD: your_password
SMTP_FROM_ADDRESS: aptabase@example.com
# Linux needs an explicit alias for host.docker.internal
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
events-db-data:
1
2
su - postgres
psql
1
2
CREATE ROLE aptabase WITH LOGIN PASSWORD 'your_password';
CREATE DATABASE aptabase OWNER aptabase;
1
2
3
\q
exit # switch to root
docker compose up -d

Nginx configuration

1
vim /etc/nginx/sites-available/aptabase.example.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 1. Plain-HTTP → HTTPS redirect
server {
listen 80;
listen [::]:80;
server_name aptabase.example.com;

# HSTS preload requires HTTPS first, so redirect early.
return 301 https://$host$request_uri;
}

# 2. HTTPS reverse-proxy
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name aptabase.example.com;

# --- TLS ---
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

# Allow modern protocols
ssl_protocols TLSv1.2 TLSv1.3;

# HSTS (optional, enables preload after 6 months)
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;

# --- Proxy settings ---
location / {
proxy_pass http://localhost:8000; # Aptabase backend
proxy_set_header Host $host; # preserve original Host
proxy_set_header X-Real-IP $remote_addr; # client IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection ""; # enable keep-alive
}

# Optional: gzip or Brotli static compression, client_max_body_size, etc.
}

1
2
ln -s /etc/nginx/sites-available/aptabase.chinesefoodlab.com /etc/nginx/sites-enabled
service nginx restart

Now you can visit your website to use aptabase. This is the link guide you how to integrate it with flutter: https://aptabase.com/for-flutter. The only disadvantage is that there is no disable registeration option in aptabase. An alternative way to disable registeration is to delete smtp configure in docker compose file temprarily.

Reference

  1. https://github.com/aptabase/self-hosting?tab=readme-ov-file
  2. https://github.com/aptabase/aptabase?tab=readme-ov-file
  3. https://github.com/aptabase/aptabase/blob/main/src/Features/EnvSettings.cs