mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
* 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:
@@ -21,6 +21,10 @@ mix tablebase.fetch --path /path/to/syzygy/3-4-5 # once per host (~939 MB)
|
|||||||
export TABLEBASE_PATH=/path/to/syzygy/3-4-5 # set per environment
|
export TABLEBASE_PATH=/path/to/syzygy/3-4-5 # set per environment
|
||||||
```
|
```
|
||||||
|
|
||||||
|
On the production VPS the directory is `/opt/chesstrainer/tablebases`, owned by
|
||||||
|
the `chesstrainer` user. Set `TABLEBASE_PATH` in `/etc/chesstrainer/env` and
|
||||||
|
restart the service; the value is read at boot.
|
||||||
|
|
||||||
See [docs/tablebases.md](docs/tablebases.md) for the full reference — dev vs
|
See [docs/tablebases.md](docs/tablebases.md) for the full reference — dev vs
|
||||||
VPS paths, `mix tablebase.check`, and boot logging.
|
VPS paths, `mix tablebase.check`, and boot logging.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// Cookieless Matomo for anonymous public pages. The server only renders the
|
||||||
|
// #matomo-config element for anonymous visitors, so account and admin pages
|
||||||
|
// never load a tracker.
|
||||||
|
|
||||||
|
const OPT_OUT_KEY = "matomo_optout";
|
||||||
|
|
||||||
|
export function isOptedOut() {
|
||||||
|
try {
|
||||||
|
return localStorage.getItem(OPT_OUT_KEY) === "1";
|
||||||
|
} catch (_error) {
|
||||||
|
// If storage is unavailable we cannot remember an opt-out. Fail closed.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setOptedOut(optedOut) {
|
||||||
|
try {
|
||||||
|
if (optedOut) {
|
||||||
|
localStorage.setItem(OPT_OUT_KEY, "1");
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem(OPT_OUT_KEY);
|
||||||
|
}
|
||||||
|
} catch (_error) {
|
||||||
|
// Nothing else to do; the current page remains untracked.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateUI() {
|
||||||
|
const optOutButton = document.getElementById("analytics-opt-out");
|
||||||
|
const optInButton = document.getElementById("analytics-opt-in");
|
||||||
|
const status = document.getElementById("analytics-status");
|
||||||
|
|
||||||
|
if (!optOutButton && !optInButton && !status) return;
|
||||||
|
|
||||||
|
const optedOut = isOptedOut();
|
||||||
|
|
||||||
|
if (optOutButton) optOutButton.hidden = optedOut;
|
||||||
|
if (optInButton) optInButton.hidden = !optedOut;
|
||||||
|
if (status) {
|
||||||
|
status.textContent = optedOut
|
||||||
|
? "Analytics is currently off in this browser."
|
||||||
|
: "Analytics is currently on in this browser.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPrivatePath() {
|
||||||
|
return window.location.pathname.startsWith("/admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
function trackPageView() {
|
||||||
|
if (isPrivatePath() || isOptedOut() || !window._paq) return;
|
||||||
|
|
||||||
|
window._paq.push(["setCustomUrl", window.location.href]);
|
||||||
|
window._paq.push(["trackPageView"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadTracker() {
|
||||||
|
const config = document.getElementById("matomo-config");
|
||||||
|
if (!config || isPrivatePath() || isOptedOut()) return;
|
||||||
|
|
||||||
|
const url = config.dataset.url;
|
||||||
|
const siteId = config.dataset.siteId;
|
||||||
|
if (!url || !siteId) return;
|
||||||
|
|
||||||
|
const _paq = (window._paq = window._paq || []);
|
||||||
|
_paq.push(["disableCookies"]);
|
||||||
|
_paq.push(["setDoNotTrack", true]);
|
||||||
|
_paq.push(["trackPageView"]);
|
||||||
|
_paq.push(["setTrackerUrl", `${url}matomo.php`]);
|
||||||
|
_paq.push(["setSiteId", siteId]);
|
||||||
|
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.async = true;
|
||||||
|
script.src = `${url}matomo.js`;
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClick(event) {
|
||||||
|
const target = event.target instanceof Element ? event.target : null;
|
||||||
|
if (!target) return;
|
||||||
|
|
||||||
|
if (target.closest("#analytics-opt-out")) {
|
||||||
|
event.preventDefault();
|
||||||
|
setOptedOut(true);
|
||||||
|
updateUI();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.closest("#analytics-opt-in")) {
|
||||||
|
event.preventDefault();
|
||||||
|
setOptedOut(false);
|
||||||
|
// The tracker was not loaded while opted out. Reload to start it.
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initAnalytics() {
|
||||||
|
if (window.__matomoInitialised) return;
|
||||||
|
window.__matomoInitialised = true;
|
||||||
|
|
||||||
|
loadTracker();
|
||||||
|
window.addEventListener("phx:navigate", trackPageView);
|
||||||
|
document.addEventListener("click", handleClick);
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
import "phoenix_html";
|
import "phoenix_html";
|
||||||
// Plain-DOM mobile navigation (works on controller and LiveView pages).
|
// Plain-DOM mobile navigation (works on controller and LiveView pages).
|
||||||
import "./nav";
|
import "./nav";
|
||||||
|
// Cookieless Matomo for anonymous public pages.
|
||||||
|
import { initAnalytics } from "./analytics";
|
||||||
// Establish Phoenix Socket and LiveView configuration.
|
// Establish Phoenix Socket and LiveView configuration.
|
||||||
import { Socket } from "phoenix";
|
import { Socket } from "phoenix";
|
||||||
import { LiveSocket } from "phoenix_live_view";
|
import { LiveSocket } from "phoenix_live_view";
|
||||||
@@ -58,6 +60,8 @@ liveSocket.connect();
|
|||||||
// >> liveSocket.disableLatencySim()
|
// >> liveSocket.disableLatencySim()
|
||||||
window.liveSocket = liveSocket;
|
window.liveSocket = liveSocket;
|
||||||
|
|
||||||
|
initAnalytics();
|
||||||
|
|
||||||
// The lines below enable quality of life phoenix_live_reload
|
// The lines below enable quality of life phoenix_live_reload
|
||||||
// development features:
|
// development features:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -2,3 +2,6 @@
|
|||||||
// page. Keep this small: no Phoenix Socket, LiveView, hooks, or topbar.
|
// page. Keep this small: no Phoenix Socket, LiveView, hooks, or topbar.
|
||||||
import "phoenix_html";
|
import "phoenix_html";
|
||||||
import "./nav";
|
import "./nav";
|
||||||
|
import { initAnalytics } from "./analytics";
|
||||||
|
|
||||||
|
initAnalytics();
|
||||||
|
|||||||
@@ -121,6 +121,10 @@ if config_env() == :prod do
|
|||||||
System.get_env("SES_SECRET_ACCESS_KEY") ||
|
System.get_env("SES_SECRET_ACCESS_KEY") ||
|
||||||
raise("environment variable SES_SECRET_ACCESS_KEY is missing")
|
raise("environment variable SES_SECRET_ACCESS_KEY is missing")
|
||||||
|
|
||||||
|
config :chesstrainer, :matomo,
|
||||||
|
url: System.get_env("MATOMO_URL"),
|
||||||
|
site_id: System.get_env("MATOMO_SITE_ID")
|
||||||
|
|
||||||
config :chesstrainer, Chesstrainer.Repo,
|
config :chesstrainer, Chesstrainer.Repo,
|
||||||
# ssl: true,
|
# ssl: true,
|
||||||
url: database_url,
|
url: database_url,
|
||||||
|
|||||||
+56
-4
@@ -19,7 +19,7 @@ Internet
|
|||||||
| Elixir | 1.19.5-otp-28 |
|
| Elixir | 1.19.5-otp-28 |
|
||||||
| Rust | 1.98.1 |
|
| Rust | 1.98.1 |
|
||||||
| Node.js | 24 (asset build only) |
|
| 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 |
|
| Caddy | 2.11.9 |
|
||||||
| Docker | 29.9.3 |
|
| Docker | 29.9.3 |
|
||||||
| Docker Compose | v5.7.0 |
|
| Docker Compose | v5.7.0 |
|
||||||
@@ -137,14 +137,23 @@ SES_SECRET_ACCESS_KEY=...
|
|||||||
MATOMO_URL=https://analytics.owenrees.eu/
|
MATOMO_URL=https://analytics.owenrees.eu/
|
||||||
MATOMO_SITE_ID=6
|
MATOMO_SITE_ID=6
|
||||||
|
|
||||||
|
TABLEBASE_PATH=/opt/chesstrainer/tablebases
|
||||||
|
|
||||||
# Optional:
|
# Optional:
|
||||||
# TABLEBASE_PATH=/path/to/syzygy
|
|
||||||
# RELEASE_COOKIE=...
|
# RELEASE_COOKIE=...
|
||||||
```
|
```
|
||||||
|
|
||||||
The production endpoint binds to `127.0.0.1` only. Caddy is the public
|
The production endpoint binds to `127.0.0.1` only. Caddy is the public
|
||||||
entry point.
|
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:
|
Generate the two secrets:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -191,6 +200,49 @@ volumes:
|
|||||||
- chesstrainer_pgdata:/var/lib/postgresql
|
- 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
|
## First-time setup
|
||||||
|
|
||||||
Run as root or with sudo:
|
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:
|
The image is pinned directly in the unified compose:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
image: postgres:18.0
|
image: postgres:18.6
|
||||||
```
|
```
|
||||||
|
|
||||||
For an immutable pin, replace it with the exact digest:
|
For an immutable pin, replace it with the exact digest:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
image: postgres:18.0@sha256:...
|
image: postgres:18.6@sha256:...
|
||||||
```
|
```
|
||||||
|
|
||||||
There is no `POSTGRES_IMAGE` environment variable involved.
|
There is no `POSTGRES_IMAGE` environment variable involved.
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
#
|
#
|
||||||
# Pin the Postgres image directly in the unified file. Replace the tag with
|
# Pin the Postgres image directly in the unified file. Replace the tag with
|
||||||
# an exact digest if you want immutable image pinning:
|
# an exact digest if you want immutable image pinning:
|
||||||
# image: postgres:18.0@sha256:...
|
# image: postgres:18.6@sha256:...
|
||||||
|
|
||||||
services:
|
services:
|
||||||
chesstrainer-db:
|
chesstrainer-db:
|
||||||
container_name: chesstrainer-db
|
container_name: chesstrainer-db
|
||||||
image: postgres:18.0
|
image: postgres:18.6
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: /etc/chesstrainer/postgres.env
|
env_file: /etc/chesstrainer/postgres.env
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -201,6 +201,28 @@ main {
|
|||||||
opacity: 0.75;
|
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 {
|
.site-footer {
|
||||||
width: min(1180px, calc(100% - 48px));
|
width: min(1180px, calc(100% - 48px));
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|||||||
+100
-9
@@ -36,7 +36,7 @@
|
|||||||
<main id="main-content">
|
<main id="main-content">
|
||||||
<article class="legal">
|
<article class="legal">
|
||||||
<h1>Privacy Policy</h1>
|
<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>
|
<p>
|
||||||
Inner Square Chess is an endgame training site. This policy explains what
|
Inner Square Chess is an endgame training site. This policy explains what
|
||||||
@@ -70,6 +70,14 @@
|
|||||||
(IP address, browser, timestamps) for security and troubleshooting.
|
(IP address, browser, timestamps) for security and troubleshooting.
|
||||||
These logs are rotated regularly.
|
These logs are rotated regularly.
|
||||||
</li>
|
</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>
|
<li>
|
||||||
<strong>Messages you send us.</strong>
|
<strong>Messages you send us.</strong>
|
||||||
If you contact us, we keep the message and our reply for as long as
|
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 session cookie that keeps you signed in;</li>
|
||||||
<li>a CSRF token that protects forms from cross-site requests;</li>
|
<li>a CSRF token that protects forms from cross-site requests;</li>
|
||||||
<li>a colour-mode preference stored in your browser.</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>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
We do not use advertising cookies, third-party analytics, or cross-site
|
We do not use advertising cookies, third-party analytics, or cross-site
|
||||||
tracking. You can clear these entries at any time in your browser
|
tracking. Our analytics is self-hosted Matomo and is configured without
|
||||||
settings; doing so will sign you out and reset your colour mode.
|
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>
|
</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>
|
<h2>How we use your information</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>To create and secure your account and sign you in.</li>
|
<li>To create and secure your account and sign you in.</li>
|
||||||
<li>To run the trainer and remember your progress.</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 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 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 keep the site available, prevent abuse, and fix faults.</li>
|
||||||
<li>To respond when you ask for help.</li>
|
<li>To respond when you ask for help.</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -135,8 +174,10 @@
|
|||||||
We do not sell your personal information. We share it only with providers
|
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
|
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.
|
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
|
Self-hosted Matomo analytics is operated by us on infrastructure we
|
||||||
the rights and safety of our users.
|
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>
|
</p>
|
||||||
|
|
||||||
<h2>Retention</h2>
|
<h2>Retention</h2>
|
||||||
@@ -144,16 +185,18 @@
|
|||||||
We keep account and training data while your account is open. If you
|
We keep account and training data while your account is open. If you
|
||||||
delete your account, we remove your personal information within a
|
delete your account, we remove your personal information within a
|
||||||
reasonable period, except where we must keep records for legal, security,
|
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>
|
</p>
|
||||||
|
|
||||||
<h2>Your rights</h2>
|
<h2>Your rights</h2>
|
||||||
<p>
|
<p>
|
||||||
Depending on where you live, you may have the right to access, correct,
|
Depending on where you live, you may have the right to access, correct,
|
||||||
delete, restrict, or export your personal information, and to object to
|
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
|
some uses of it. You can object to analytics processing at any time using
|
||||||
you are in the UK or EU and are unhappy with our response, you can complain
|
the control on this page or by contacting us. To make a request, contact
|
||||||
to your local data protection authority.
|
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>
|
</p>
|
||||||
|
|
||||||
<h2>Children</h2>
|
<h2>Children</h2>
|
||||||
@@ -192,5 +235,53 @@
|
|||||||
</nav>
|
</nav>
|
||||||
<small>© 2026 Inner Square Chess</small>
|
<small>© 2026 Inner Square Chess</small>
|
||||||
</footer>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
container_name: chesstrainer_dev-db
|
container_name: chesstrainer_dev-db
|
||||||
image: postgres:18.0
|
image: postgres:18.6
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=postgres
|
- POSTGRES_USER=postgres
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
# Analytics
|
||||||
|
|
||||||
|
We use a self-hosted Matomo instance for privacy-conscious analytics on public
|
||||||
|
pages and the guest trainer.
|
||||||
|
|
||||||
|
## What is collected
|
||||||
|
|
||||||
|
- Page views on anonymous public pages and the guest trainer.
|
||||||
|
- Standard request data Matomo needs to count a visit, with IP anonymisation.
|
||||||
|
|
||||||
|
We do **not**:
|
||||||
|
|
||||||
|
- set Matomo cookies,
|
||||||
|
- use user IDs,
|
||||||
|
- track signed-in account, profile, or admin pages,
|
||||||
|
- enable cross-site or advertising features,
|
||||||
|
- share analytics data with third parties.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
The app reads these environment variables at boot:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
MATOMO_URL=https://analytics.owenrees.eu/
|
||||||
|
MATOMO_SITE_ID=6
|
||||||
|
```
|
||||||
|
|
||||||
|
They are configured in `config/runtime.exs` for production only. If either is
|
||||||
|
missing, no analytics config is rendered and no tracker is loaded.
|
||||||
|
|
||||||
|
The root layout renders a hidden `#matomo-config` element only when the visitor
|
||||||
|
is anonymous. `assets/js/analytics.js` initialises Matomo cookieless from that
|
||||||
|
element. Signed-in users never receive the element.
|
||||||
|
|
||||||
|
## Matomo settings
|
||||||
|
|
||||||
|
In the Matomo administration UI:
|
||||||
|
|
||||||
|
1. **Administration → Websites → Manage**
|
||||||
|
- URL: `https://innersquare.app`
|
||||||
|
- Site ID: `6`
|
||||||
|
- Timezone: match the site
|
||||||
|
2. **Administration → Privacy → Anonymize data**
|
||||||
|
- Enable IP anonymisation (at least the last byte; 2 bytes is safer)
|
||||||
|
- Disable tracking cookies
|
||||||
|
- Respect Do Not Track
|
||||||
|
- Do not use user IDs
|
||||||
|
- Set raw data retention to **180 days**
|
||||||
|
3. **Administration → System check / trusted hosts**
|
||||||
|
- Add `innersquare.app` and `www.innersquare.app` if host validation is on.
|
||||||
|
4. Do not enable ecommerce, advertising, or cross-domain tracking.
|
||||||
|
|
||||||
|
The JavaScript also calls:
|
||||||
|
|
||||||
|
```js
|
||||||
|
_paq.push(["disableCookies"]);
|
||||||
|
_paq.push(["setDoNotTrack", true]);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Opt-out
|
||||||
|
|
||||||
|
The privacy page has an **Analytics** section with an opt-out control. The
|
||||||
|
preference is stored in `localStorage["matomo_optout"]`, not a cookie. When set,
|
||||||
|
the tracker is never loaded and LiveView page views are skipped.
|
||||||
|
|
||||||
|
The preference is local to the browser. Clearing site data resets it. Users can
|
||||||
|
also object by emailing `support@innersquare.app`.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
On an anonymous public page:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -s https://innersquare.app/ | grep -c matomo-config
|
||||||
|
```
|
||||||
|
|
||||||
|
should return `1`.
|
||||||
|
|
||||||
|
In the browser:
|
||||||
|
|
||||||
|
- `matomo.js` and `matomo.php` load once.
|
||||||
|
- Matomo Real-time shows the page view.
|
||||||
|
- No `_pk_*` cookies are created.
|
||||||
|
- Opting out sets `matomo_optout=1` in localStorage and stops further requests.
|
||||||
|
- Signed-in pages produce no Matomo config or requests.
|
||||||
|
- A DNT browser setting suppresses tracking.
|
||||||
|
|
||||||
|
## Legal basis
|
||||||
|
|
||||||
|
Analytics runs on the basis of legitimate interests in improving the service.
|
||||||
|
The privacy policy discloses it, explains the data, and provides the opt-out.
|
||||||
|
This document is an engineering configuration guide, not legal advice; keep a
|
||||||
|
short legitimate-interest assessment on file.
|
||||||
+19
-2
@@ -23,10 +23,27 @@ machine and a VPS will point at different copies.
|
|||||||
export TABLEBASE_PATH=/home/you/Downloads/tablebase
|
export TABLEBASE_PATH=/home/you/Downloads/tablebase
|
||||||
mix phx.server
|
mix phx.server
|
||||||
|
|
||||||
# Production (release)
|
# Production (release), behind systemd
|
||||||
TABLEBASE_PATH=/data/syzygy/3-4-5 bin/chesstrainer start
|
TABLEBASE_PATH=/opt/chesstrainer/tablebases bin/chesstrainer start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
On the production VPS the directory is `/opt/chesstrainer/tablebases`, owned by
|
||||||
|
the `chesstrainer` user. Set `TABLEBASE_PATH` in `/etc/chesstrainer/env` rather
|
||||||
|
than an interactive shell, then restart `chesstrainer.service` — the value is
|
||||||
|
read at boot.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo chown -R chesstrainer:chesstrainer /opt/chesstrainer/tablebases
|
||||||
|
sudo chmod -R u=rwX,g=rX,o= /opt/chesstrainer/tablebases
|
||||||
|
sudo systemctl restart chesstrainer
|
||||||
|
curl -s http://127.0.0.1:4100/health
|
||||||
|
```
|
||||||
|
|
||||||
|
Healthy local tablebases report `tablebase: "local"` and `status: "ok"`. A
|
||||||
|
missing, empty, or unreadable directory reports `tablebase: "fallback"` or
|
||||||
|
`"not_configured"` and `status: "degraded"`, still with HTTP 200 because the
|
||||||
|
Lichess fallback is available.
|
||||||
|
|
||||||
The value must reach the process. A bare `TABLEBASE_PATH=...` line in bash
|
The value must reach the process. A bare `TABLEBASE_PATH=...` line in bash
|
||||||
only sets a shell variable and is **not** exported to `mix` or the release —
|
only sets a shell variable and is **not** exported to `mix` or the release —
|
||||||
use `export`, or prefix the command. For a release, systemd unit or container,
|
use `export`, or prefix the command. For a release, systemd unit or container,
|
||||||
|
|||||||
@@ -296,4 +296,48 @@ defmodule ChesstrainerWeb.Layouts do
|
|||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders the Matomo configuration for anonymous public pages.
|
||||||
|
|
||||||
|
The actual tracker is initialised by `assets/js/analytics.js`. Signed-in
|
||||||
|
visitors never get the config element, so account and admin pages are not
|
||||||
|
tracked.
|
||||||
|
"""
|
||||||
|
attr :current_scope, :map, default: nil
|
||||||
|
|
||||||
|
def analytics(assigns) do
|
||||||
|
config = Application.get_env(:chesstrainer, :matomo, [])
|
||||||
|
url = normalize_matomo_url(config[:url])
|
||||||
|
site_id = config[:site_id]
|
||||||
|
user = Map.get(assigns, :current_scope) && assigns.current_scope.user
|
||||||
|
|
||||||
|
assigns =
|
||||||
|
assign(assigns,
|
||||||
|
matomo_url: url,
|
||||||
|
matomo_site_id: site_id && to_string(site_id),
|
||||||
|
analytics_enabled:
|
||||||
|
is_binary(url) and url != "" and site_id not in [nil, ""] and is_nil(user)
|
||||||
|
)
|
||||||
|
|
||||||
|
~H"""
|
||||||
|
<div
|
||||||
|
:if={@analytics_enabled}
|
||||||
|
id="matomo-config"
|
||||||
|
data-url={@matomo_url}
|
||||||
|
data-site-id={@matomo_site_id}
|
||||||
|
hidden
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
defp normalize_matomo_url(url) when is_binary(url) do
|
||||||
|
case String.trim(url) do
|
||||||
|
"" -> nil
|
||||||
|
url -> String.trim_trailing(url, "/") <> "/"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp normalize_matomo_url(_url), do: nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -76,5 +76,6 @@
|
|||||||
<Layouts.navbar current_scope={@current_scope} />
|
<Layouts.navbar current_scope={@current_scope} />
|
||||||
{@inner_content}
|
{@inner_content}
|
||||||
<Layouts.footer />
|
<Layouts.footer />
|
||||||
|
<Layouts.analytics current_scope={@current_scope} />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<main>
|
<main>
|
||||||
<article class="legal">
|
<article class="legal">
|
||||||
<h1>Privacy Policy</h1>
|
<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>
|
<p>
|
||||||
{Branding.name()} is an endgame training site. This policy explains what
|
{Branding.name()} is an endgame training site. This policy explains what
|
||||||
@@ -37,6 +37,14 @@
|
|||||||
(IP address, browser, timestamps) for security and troubleshooting.
|
(IP address, browser, timestamps) for security and troubleshooting.
|
||||||
These logs are rotated regularly.
|
These logs are rotated regularly.
|
||||||
</li>
|
</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>
|
<li>
|
||||||
<strong>Messages you send us.</strong>
|
<strong>Messages you send us.</strong>
|
||||||
If you contact us, we keep the message and our reply for as long as
|
If you contact us, we keep the message and our reply for as long as
|
||||||
@@ -53,19 +61,62 @@
|
|||||||
<li>a session cookie that keeps you signed in;</li>
|
<li>a session cookie that keeps you signed in;</li>
|
||||||
<li>a CSRF token that protects forms from cross-site requests;</li>
|
<li>a CSRF token that protects forms from cross-site requests;</li>
|
||||||
<li>a colour-mode preference stored in your browser.</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>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
We do not use advertising cookies, third-party analytics, or cross-site
|
We do not use advertising cookies, third-party analytics, or cross-site
|
||||||
tracking. You can clear these entries at any time in your browser
|
tracking. Our analytics is self-hosted Matomo and is configured without
|
||||||
settings; doing so will sign you out and reset your colour mode.
|
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>
|
</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:" <> Branding.support_email()}>{Branding.support_email()}</a>.
|
||||||
|
</p>
|
||||||
|
<p id="analytics-status">Analytics is currently on in this browser.</p>
|
||||||
|
<div class="flex flex-wrap gap-3">
|
||||||
|
<button
|
||||||
|
id="analytics-opt-out"
|
||||||
|
type="button"
|
||||||
|
class="inline-flex items-center justify-center rounded-md border border-base-300 bg-base-100 px-4 py-2 text-sm font-semibold text-base-content hover:bg-base-200"
|
||||||
|
>
|
||||||
|
Opt out of analytics
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
id="analytics-opt-in"
|
||||||
|
type="button"
|
||||||
|
hidden
|
||||||
|
class="inline-flex items-center justify-center rounded-md border border-base-300 bg-base-100 px-4 py-2 text-sm font-semibold text-base-content hover:bg-base-200"
|
||||||
|
>
|
||||||
|
Opt back in
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2>How we use your information</h2>
|
<h2>How we use your information</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>To create and secure your account and sign you in.</li>
|
<li>To create and secure your account and sign you in.</li>
|
||||||
<li>To run the trainer and remember your progress.</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 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 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 keep the site available, prevent abuse, and fix faults.</li>
|
||||||
<li>To respond when you ask for help.</li>
|
<li>To respond when you ask for help.</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -102,8 +153,10 @@
|
|||||||
We do not sell your personal information. We share it only with providers
|
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
|
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.
|
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
|
Self-hosted Matomo analytics is operated by us on infrastructure we
|
||||||
the rights and safety of our users.
|
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>
|
</p>
|
||||||
|
|
||||||
<h2>Retention</h2>
|
<h2>Retention</h2>
|
||||||
@@ -111,16 +164,18 @@
|
|||||||
We keep account and training data while your account is open. If you
|
We keep account and training data while your account is open. If you
|
||||||
delete your account, we remove your personal information within a
|
delete your account, we remove your personal information within a
|
||||||
reasonable period, except where we must keep records for legal, security,
|
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>
|
</p>
|
||||||
|
|
||||||
<h2>Your rights</h2>
|
<h2>Your rights</h2>
|
||||||
<p>
|
<p>
|
||||||
Depending on where you live, you may have the right to access, correct,
|
Depending on where you live, you may have the right to access, correct,
|
||||||
delete, restrict, or export your personal information, and to object to
|
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
|
some uses of it. You can object to analytics processing at any time using
|
||||||
you are in the UK or EU and are unhappy with our response, you can complain
|
the control on this page or by contacting us. To make a request, contact
|
||||||
to your local data protection authority.
|
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>
|
</p>
|
||||||
|
|
||||||
<h2>Children</h2>
|
<h2>Children</h2>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule ChesstrainerWeb.LayoutsTest do
|
defmodule ChesstrainerWeb.LayoutsTest do
|
||||||
use ChesstrainerWeb.ConnCase, async: true
|
use ChesstrainerWeb.ConnCase, async: false
|
||||||
|
|
||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest
|
||||||
|
|
||||||
@@ -66,4 +66,48 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
|||||||
refute html =~ ~r/<button[^>]*class="nav-cta"/
|
refute html =~ ~r/<button[^>]*class="nav-cta"/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "analytics/1" do
|
||||||
|
setup do
|
||||||
|
previous = Application.get_env(:chesstrainer, :matomo)
|
||||||
|
on_exit(fn -> restore_env(:matomo, previous) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders the Matomo config for anonymous visitors" do
|
||||||
|
Application.put_env(:chesstrainer, :matomo,
|
||||||
|
url: "https://analytics.owenrees.eu/",
|
||||||
|
site_id: "6"
|
||||||
|
)
|
||||||
|
|
||||||
|
html = render_component(&Layouts.analytics/1, %{current_scope: nil})
|
||||||
|
|
||||||
|
assert html =~ ~s(id="matomo-config")
|
||||||
|
assert html =~ ~s(data-url="https://analytics.owenrees.eu/")
|
||||||
|
assert html =~ ~s(data-site-id="6")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not render for signed-in users" do
|
||||||
|
Application.put_env(:chesstrainer, :matomo,
|
||||||
|
url: "https://analytics.owenrees.eu/",
|
||||||
|
site_id: "6"
|
||||||
|
)
|
||||||
|
|
||||||
|
scope = Scope.for_user(%User{username: "alice"})
|
||||||
|
html = render_component(&Layouts.analytics/1, %{current_scope: scope})
|
||||||
|
|
||||||
|
refute html =~ ~s(id="matomo-config")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not render when Matomo is unconfigured" do
|
||||||
|
Application.delete_env(:chesstrainer, :matomo)
|
||||||
|
|
||||||
|
html = render_component(&Layouts.analytics/1, %{current_scope: nil})
|
||||||
|
|
||||||
|
refute html =~ ~s(id="matomo-config")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restore_env(key, nil), do: Application.delete_env(:chesstrainer, key)
|
||||||
|
defp restore_env(key, value), do: Application.put_env(:chesstrainer, key, value)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -99,9 +99,13 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
|||||||
document = LazyHTML.from_document(html)
|
document = LazyHTML.from_document(html)
|
||||||
|
|
||||||
assert LazyHTML.text(LazyHTML.query(document, "h1")) == "Privacy Policy"
|
assert LazyHTML.text(LazyHTML.query(document, "h1")) == "Privacy Policy"
|
||||||
assert html =~ "Last updated: 6 November 2026"
|
assert html =~ "Last updated: 10 November 2026"
|
||||||
assert html =~ "What we collect"
|
assert html =~ "What we collect"
|
||||||
assert html =~ "Cookies and local storage"
|
assert html =~ "Cookies and local storage"
|
||||||
|
assert html =~ "Analytics"
|
||||||
|
assert html =~ "self-hosted Matomo"
|
||||||
|
assert html =~ "without cookies"
|
||||||
|
assert html =~ ~s(id="analytics-opt-out")
|
||||||
assert html =~ "Guest puzzle limit"
|
assert html =~ "Guest puzzle limit"
|
||||||
assert html =~ "HMAC-SHA256"
|
assert html =~ "HMAC-SHA256"
|
||||||
assert html =~ "Article 6(1)(f) GDPR"
|
assert html =~ "Article 6(1)(f) GDPR"
|
||||||
|
|||||||
Reference in New Issue
Block a user