Add cookieless Matomo analytics and opt-out (#131) (#133)

* Align Postgres version on 18.6

* Document production tablebase path and permissions

* Add cookieless Matomo analytics with opt-out (#131)
This commit is contained in:
2026-11-10 10:12:48 +01:00
committed by GitHub
parent be57f21729
commit 73ba25afe3
17 changed files with 572 additions and 29 deletions
+56 -4
View File
@@ -19,7 +19,7 @@ Internet
| Elixir | 1.19.5-otp-28 |
| Rust | 1.98.1 |
| Node.js | 24 (asset build only) |
| Postgres | `postgres:18.0`, pinned directly in the unified compose |
| Postgres | `postgres:18.6`, pinned directly in the unified compose |
| Caddy | 2.11.9 |
| Docker | 29.9.3 |
| Docker Compose | v5.7.0 |
@@ -137,14 +137,23 @@ SES_SECRET_ACCESS_KEY=...
MATOMO_URL=https://analytics.owenrees.eu/
MATOMO_SITE_ID=6
TABLEBASE_PATH=/opt/chesstrainer/tablebases
# Optional:
# TABLEBASE_PATH=/path/to/syzygy
# RELEASE_COOKIE=...
```
The production endpoint binds to `127.0.0.1` only. Caddy is the public
entry point.
## Matomo analytics
Set `MATOMO_URL` and `MATOMO_SITE_ID` to enable cookieless analytics on public
pages and the guest trainer. Signed-in account and admin pages are excluded.
The privacy controls, Matomo server settings, retention, and opt-out behaviour
are documented in `docs/analytics.md`.
Generate the two secrets:
```sh
@@ -191,6 +200,49 @@ volumes:
- chesstrainer_pgdata:/var/lib/postgresql
```
## Local tablebases (optional)
The production tablebase directory is `/opt/chesstrainer/tablebases`. Keep the
`.rtbw`/`.rtbz` files flat in that directory, and make sure the `chesstrainer`
user can read them:
```sh
sudo install -d -o chesstrainer -g chesstrainer /opt/chesstrainer/tablebases
sudo chown -R chesstrainer:chesstrainer /opt/chesstrainer/tablebases
sudo chmod -R u=rwX,g=rX,o= /opt/chesstrainer/tablebases
```
Set the path in `/etc/chesstrainer/env`:
```sh
TABLEBASE_PATH=/opt/chesstrainer/tablebases
```
Then restart the service, because `TABLEBASE_PATH` is read at boot:
```sh
sudo systemctl restart chesstrainer
```
Check `/health`. It should move from `degraded` / `not_configured` to
`ok` / `local`:
```sh
curl -s http://127.0.0.1:4100/health
sudo journalctl -u chesstrainer -n 50 --no-pager | grep -i tablebase
```
If the path is missing, unreadable, or empty, the app falls back to Lichess and
health stays `degraded` but still returns 200.
To refresh the files:
```sh
mix tablebase.fetch --path /opt/chesstrainer/tablebases
sudo chown -R chesstrainer:chesstrainer /opt/chesstrainer/tablebases
sudo systemctl restart chesstrainer
```
## First-time setup
Run as root or with sudo:
@@ -223,13 +275,13 @@ Add the `chesstrainer-db` service and `chesstrainer_pgdata` volume from
The image is pinned directly in the unified compose:
```yaml
image: postgres:18.0
image: postgres:18.6
```
For an immutable pin, replace it with the exact digest:
```yaml
image: postgres:18.0@sha256:...
image: postgres:18.6@sha256:...
```
There is no `POSTGRES_IMAGE` environment variable involved.
+2 -2
View File
@@ -3,12 +3,12 @@
#
# Pin the Postgres image directly in the unified file. Replace the tag with
# an exact digest if you want immutable image pinning:
# image: postgres:18.0@sha256:...
# image: postgres:18.6@sha256:...
services:
chesstrainer-db:
container_name: chesstrainer-db
image: postgres:18.0
image: postgres:18.6
restart: unless-stopped
env_file: /etc/chesstrainer/postgres.env
ports:
+22
View File
@@ -201,6 +201,28 @@ main {
opacity: 0.75;
}
.analytics-buttons {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 16px;
}
.analytics-buttons button {
padding: 10px 16px;
border: 1px solid var(--color-hairline);
border-radius: 8px;
background: var(--color-canvas-raised);
color: var(--color-body);
font: inherit;
font-weight: 600;
cursor: pointer;
}
.analytics-buttons button:hover {
background: var(--color-canvas);
}
.site-footer {
width: min(1180px, calc(100% - 48px));
margin: 0 auto;
+100 -9
View File
@@ -36,7 +36,7 @@
<main id="main-content">
<article class="legal">
<h1>Privacy Policy</h1>
<p class="legal-meta">Last updated: 6 November 2026</p>
<p class="legal-meta">Last updated: 10 November 2026</p>
<p>
Inner Square Chess is an endgame training site. This policy explains what
@@ -70,6 +70,14 @@
(IP address, browser, timestamps) for security and troubleshooting.
These logs are rotated regularly.
</li>
<li>
<strong>Usage data.</strong>
On public pages and the guest trainer, we use a self-hosted Matomo
instance to understand aggregate usage. Matomo is configured without
cookies, with IP anonymisation, and to respect Do Not Track. We do
not use user IDs, track signed-in account pages, or share this data
with third parties.
</li>
<li>
<strong>Messages you send us.</strong>
If you contact us, we keep the message and our reply for as long as
@@ -86,19 +94,50 @@
<li>a session cookie that keeps you signed in;</li>
<li>a CSRF token that protects forms from cross-site requests;</li>
<li>a colour-mode preference stored in your browser.</li>
<li>
an analytics opt-out preference stored in your browser's local
storage, if you choose to opt out.
</li>
</ul>
<p>
We do not use advertising cookies, third-party analytics, or cross-site
tracking. You can clear these entries at any time in your browser
settings; doing so will sign you out and reset your colour mode.
tracking. Our analytics is self-hosted Matomo and is configured without
cookies. You can clear these entries at any time in your browser
settings; doing so will sign you out, reset your colour mode, and reset
your analytics preference.
</p>
<h2>Analytics</h2>
<p>
We use a self-hosted Matomo instance at
<a href="https://analytics.owenrees.eu/">analytics.owenrees.eu</a>
to understand aggregate use of the public site and guest trainer. It is
configured without cookies, with IP anonymisation, and to respect Do
Not Track. We do not use user IDs, track signed-in account pages, or
share this data with third parties.
</p>
<p>
Raw analytics data is retained for up to 180 days. We process it on the
basis of our legitimate interests in improving the service. You can
object at any time using the control below or by emailing
<a href="mailto:support@innersquare.app">support@innersquare.app</a>.
</p>
<p id="analytics-status">Analytics is currently on in this browser.</p>
<div class="analytics-buttons">
<button id="analytics-opt-out" type="button">Opt out of analytics</button>
<button id="analytics-opt-in" type="button" hidden>Opt back in</button>
</div>
<h2>How we use your information</h2>
<ul>
<li>To create and secure your account and sign you in.</li>
<li>To run the trainer and remember your progress.</li>
<li>To send service emails, such as confirmation and password reset links.</li>
<li>To send occasional endgame tips and site news, if you opted in.</li>
<li>
To understand aggregate use of the public site and guest trainer, and
improve the service.
</li>
<li>To keep the site available, prevent abuse, and fix faults.</li>
<li>To respond when you ask for help.</li>
</ul>
@@ -135,8 +174,10 @@
We do not sell your personal information. We share it only with providers
who help us run the site — for example hosting, database, and email
delivery providers — and only as far as they need it to perform that work.
We may also disclose information where the law requires it or to protect
the rights and safety of our users.
Self-hosted Matomo analytics is operated by us on infrastructure we
control; we do not share that data with third parties. We may also
disclose information where the law requires it or to protect the rights
and safety of our users.
</p>
<h2>Retention</h2>
@@ -144,16 +185,18 @@
We keep account and training data while your account is open. If you
delete your account, we remove your personal information within a
reasonable period, except where we must keep records for legal, security,
or accounting reasons.
or accounting reasons. We retain raw analytics data for up to 180 days.
</p>
<h2>Your rights</h2>
<p>
Depending on where you live, you may have the right to access, correct,
delete, restrict, or export your personal information, and to object to
some uses of it. To make a request, contact us using the address below. If
you are in the UK or EU and are unhappy with our response, you can complain
to your local data protection authority.
some uses of it. You can object to analytics processing at any time using
the control on this page or by contacting us. To make a request, contact
us using the address below. If you are in the UK or EU and are unhappy
with our response, you can complain to your local data protection
authority.
</p>
<h2>Children</h2>
@@ -192,5 +235,53 @@
</nav>
<small>&copy; 2026 Inner Square Chess</small>
</footer>
<script>
(function () {
var key = "matomo_optout";
var optOut = document.getElementById("analytics-opt-out");
var optIn = document.getElementById("analytics-opt-in");
var status = document.getElementById("analytics-status");
function optedOut() {
try {
return localStorage.getItem(key) === "1";
} catch (error) {
return true;
}
}
function update() {
var off = optedOut();
if (optOut) optOut.hidden = off;
if (optIn) optIn.hidden = !off;
if (status) {
status.textContent = off
? "Analytics is currently off in this browser."
: "Analytics is currently on in this browser.";
}
}
if (optOut) {
optOut.addEventListener("click", function () {
try {
localStorage.setItem(key, "1");
} catch (error) {}
update();
});
}
if (optIn) {
optIn.addEventListener("click", function () {
try {
localStorage.removeItem(key);
} catch (error) {}
update();
});
}
update();
})();
</script>
</body>
</html>