Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ jobs:
"test_status_verdict",
"test_streaming_settings",
"test_sx_report",
"test_telemetry",
"test_time_format",
"test_updater",
"test_updater_paths"
"test_updater", "test_updater_paths"
)
$failed = @()
foreach ($s in $scripts) {
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ plain English a non-technical operator can understand.

## [Unreleased]

### Changed
- **Anonymous usage counts are now off unless you say yes.** Before this, the
web page reported which screens were used and attached your **station name**
to it. Now nothing is sent until someone opts in: the last step of the setup
wizard asks once (unchecked), and **Settings → About & updates** has the
switch, which an admin can turn either way at any time.
* When it is on, the page reports which features are used, tagged with a
**random install ID** generated once — never the station name, a file path,
an IP address, a user name or any song data.
* An existing install has no setting for this, and a missing setting counts
as **off** — upgrading a station never starts sending anything.
* Nothing on the playout path has network code, so this cannot touch audio
either way. While it is off the tracking tag is not rendered at all.

## [1.6.4] - 2026-11-07

### Added
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@ users and history.

## Telemetry & privacy

The web GUI includes Google Analytics (GA4) usage telemetry so we can see
which features stations actually use. What this means in practice:
Telemetry is **off unless you turn it on**. Nothing leaves the box while it is
off — the tracking tag is not even rendered into the page. What this means in
practice:

- It runs **only in the browser GUI** — the audio engine and playout path
never send anything, and playback is never affected.
- The data is feature usage (pages and actions in the GUI), with your
**station name** attached so we can tell deployments apart. No listener
data, no audio, no library contents.
- If you turn it on (the setup wizard asks once, and
**Settings → About & updates** changes it later), the page reports **which
features are used**, tagged with a **random install ID** generated once and
stored in `config\config.json`. Your station name is never sent — nor a file
path, an IP address, a user name or any song data.
- With no internet connection, the tag simply never loads and the GUI works
identically.
- **Opting out** is one line in `config\config.json`:
`"core": { "ga_measurement_id": "" }` — or set your own GA4 measurement ID
there to send usage data to your own property instead.
- An existing config with no `telemetry_enabled` key counts as **off**, so
upgrading never opts a station in.
- To send the counts to your own GA4 property instead, set
`"core": { "telemetry_enabled": true, "ga_measurement_id": "<your id>" }`.

## Architecture (the short version)

Expand Down
22 changes: 22 additions & 0 deletions config/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ exists so old playlists that contain `Z:\...` keep playing.
| `feed_ahead_tracks` | How far ahead of the play head the engine queue is fed. | `3` |
| `allow_gui_restart` | Shows a "restart everything" button in the UI. Set `false` on an on-air PC so nobody can drop audio from a browser. | `true` |
| `update_check` | Look for a newer release every few hours. | `true` |
| `telemetry_enabled` | Anonymous feature-usage counts from the web page. **Off unless you say yes** — asked once in the setup wizard, changeable in Settings. Missing key = off. | `false` |
| `telemetry_install_id` | The random ID the usage counts are tagged with. Created automatically the first time telemetry is turned on; contains nothing about your station or PC. | empty |
| `ga_measurement_id` | Send the counts to your own GA4 property instead of ours. Only used when `telemetry_enabled` is true. | empty (ours) |

### Telemetry — what is and is not sent

Feature-usage counting runs **only in the web page**, and only when
`telemetry_enabled` is `true`. It is asked once at the end of the setup wizard
(unchecked by default) and can be changed at any time in
**Settings → About & updates**.

- **Sent:** which screens and features the browser opens, tagged with
`telemetry_install_id` — a random value minted the first time telemetry is
turned on.
- **Never sent:** your station name, any file path, IP addresses, user names,
song data or listener data.
- **When the switch is off, nothing is sent at all** — the tracking tag is not
even rendered into the page.
- **Nothing on the playout path has network code**, so this can never affect
audio, and the GUI works identically with no internet connection.
- **A config written before this setting existed has no `telemetry_enabled`
key, and a missing key means off** — upgrading a station never opts it in.

## `nowplaying_push` — song titles to your stream host (optional)

Expand Down
3 changes: 2 additions & 1 deletion config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"bind_host": "0.0.0.0",
"bind_port": 8080,
"precache_target_minutes": 45,
"feed_ahead_tracks": 3
"feed_ahead_tracks": 3,
"telemetry_enabled": false
},
"poller": {
"interval_sec": 60,
Expand Down
52 changes: 49 additions & 3 deletions services/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ def create_app(cfg: dict) -> FastAPI:
templates = Jinja2Templates(directory=os.path.join(WEB, "templates"))
# env globals so EVERY render (routers included) sees them without
# threading extra ctx through each handler
templates.env.globals["ga_id"] = cfg.get("ga_measurement_id") or ""
templates.env.globals["ga_station"] = cfg["station_name"]
#
# Telemetry is OPT-IN. ``ga_id`` is empty unless an operator turned it on,
# and base.html keys the entire GA4 tag off it — so an untouched install
# ships no tracking script at all. ``ga_install_id`` is a random value
# minted at opt-in; the station name is deliberately NOT exposed to the
# templates, so it cannot ride along on anything that leaves the box.
def _telemetry_globals(c: dict) -> None:
on = bool(c.get("telemetry_enabled")) and bool(c.get("telemetry_install_id"))
templates.env.globals["ga_id"] = (c.get("ga_measurement_id") or "") if on else ""
templates.env.globals["ga_install_id"] = (
(c.get("telemetry_install_id") or "") if on else "")
_telemetry_globals(cfg)
# cache-buster for /static/style.css: after an update the browser fetches
# the new stylesheet instead of showing the old layout until a hard refresh
# (read on every render — one stat — so a stylesheet updated while the
Expand All @@ -95,6 +105,7 @@ def __str__(self):
app.state.cfg = cfg
app.state.sessions = sessions
app.state.templates = templates
app.state.refresh_telemetry = _telemetry_globals
app.mount("/static", StaticFiles(directory=os.path.join(WEB, "static")),
name="static")

Expand Down Expand Up @@ -233,7 +244,7 @@ def api_setup_state(request: Request, conn=Depends(get_conn)):
@app.post("/api/setup/step")
def api_setup_step(request: Request, body: dict, conn=Depends(get_conn)):
"""Save one wizard step, then move to the next one."""
from .config import load_config, update_config
from .config import load_config, update_config, set_telemetry
from . import playlists as pl
step = (body.get("step") or "").strip()
values = body.get("values") or {}
Expand Down Expand Up @@ -284,6 +295,17 @@ def api_setup_step(request: Request, body: dict, conn=Depends(get_conn)):
db.set_setting(conn, nowplaying_file.K_PATH,
(values.get("np_file") or "").strip())
elif step == "done":
# Telemetry is asked ONCE, here, and the checkbox is unchecked by
# default. An absent answer (Skip, or a stale wizard page in
# another tab) changes nothing, so nobody is ever opted in by
# omission — only an explicit tick sends anything.
if "telemetry" in values:
t = set_telemetry(bool(values.get("telemetry")))
_telemetry_globals({
"telemetry_enabled": t["enabled"],
"telemetry_install_id": t["install_id"],
"ga_measurement_id": t["measurement_id"],
})
setup_mod.complete(conn)
return {"ok": True, "next": "done", "complete": True}
else:
Expand Down Expand Up @@ -518,6 +540,30 @@ def set_time_format(body: dict, conn=Depends(get_conn), _=Depends(api_user)):
sched.set_hour12(fmt == "12") # live — affects the next label render
return {"ok": True, "format": fmt}

# ---- anonymous feature-usage telemetry (opt-in, admin only)
@app.get("/api/settings/telemetry")
def get_telemetry(conn=Depends(get_conn), _=Depends(api_user)):
"""Off unless someone turned it on. The install ID is shown so an
operator can see exactly what identifier their box would report."""
from .config import load_config
c = load_config()
return {"enabled": bool(c.get("telemetry_enabled")),
"install_id": c.get("telemetry_install_id") or ""}

@app.post("/api/settings/telemetry")
def set_telemetry_settings(body: dict, _=Depends(api_admin)):
"""Turn feature-usage counting on or off. Admin only: it is a change to
what the station reports about itself, not a display preference."""
from .config import set_telemetry
t = set_telemetry(bool((body or {}).get("enabled")))
_telemetry_globals({
"telemetry_enabled": t["enabled"],
"telemetry_install_id": t["install_id"],
"ga_measurement_id": t["measurement_id"],
})
return {"ok": True, "enabled": t["enabled"],
"install_id": t["install_id"]}

# ---- user administration (admin only: the one thing Basic can't do)
def _norm_role(r: str | None) -> str | None:
r = (r or "").strip().lower()
Expand Down
78 changes: 71 additions & 7 deletions services/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,77 @@
import json
import logging
import os
import uuid

ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
log = logging.getLogger("core.config")

# Product telemetry: GA4 measurement ID baked into every install so feature
# usage across customer stations lands in one property (station_name rides
# along as a user property). A station can override with its own ID — or
# disable entirely with "core": {"ga_measurement_id": ""} — in config.json.
# The GUI works identically offline; the tag just never loads.
# Product telemetry: GA4 feature-usage counting in the WEB GUI — and it is
# OFF unless the operator says yes. The setup wizard's Done step asks once
# (unchecked) and Settings -> About & updates can change it later.
#
# What may leave the box when it is on: which screens/features the browser
# opened, tagged with a random install ID minted once at opt-in. What must
# NEVER leave: the station name, any file path, IP, user name or song data.
# Nothing on the playout path has network code at all, so telemetry can never
# touch audio; with the switch off, base.html renders no tag whatsoever.
GA_MEASUREMENT_ID_DEFAULT = "G-3BK3GZDSJN" # StudioFire GA4 property (VeteranOp)


def load_telemetry(core: dict | None = None) -> dict:
"""Telemetry state for a ``core`` config block. Absent key means OFF.

``telemetry_enabled`` is the only switch. Every config written before
opt-in existed lacks it, so an upgraded station stays silent until a human
ticks the box — that is the whole compatibility story.

``telemetry_install_id`` is the only identifier that reaches GA4. It is
minted at opt-in and contains nothing about the station or the machine.

``measurement_id`` comes back EMPTY unless telemetry is on; ``base.html``
keys the whole tag off it, so an empty value means no script at all.
"""
core = core or {}
enabled = bool(core.get("telemetry_enabled", False))
own_property = str(core.get("ga_measurement_id") or "").strip()
return {
"enabled": enabled,
"install_id": str(core.get("telemetry_install_id") or "").strip(),
"measurement_id": ((own_property or GA_MEASUREMENT_ID_DEFAULT)
if enabled else ""),
}


def new_install_id() -> str:
"""A random install identifier — no hostname, MAC, path or user in it."""
return uuid.uuid4().hex


def set_telemetry(enabled: bool, path: str | None = None) -> dict:
"""Turn feature-usage telemetry on or off; mint the install ID once.

Turning it on mints ``telemetry_install_id`` if there is not one already,
and turning it off keeps the ID so re-opting-in stays the same install.
Written atomically through ``update_config`` because the web service reads
this file on every request.
"""
p = (path or os.environ.get("STUDIOFIRE_CONFIG")
or os.path.join(ROOT, "config", "config.json"))
core: dict = {}
try:
with open(p, encoding="utf-8") as fh:
core = (json.load(fh).get("core") or {})
except (OSError, ValueError):
core = {}
values: dict = {"telemetry_enabled": bool(enabled)}
if enabled and not str(core.get("telemetry_install_id") or "").strip():
values["telemetry_install_id"] = new_install_id()
update_config({"core": values}, p)
merged = dict(core)
merged.update(values)
return load_telemetry(merged)


# Now-playing push (#747): off-box, feature-flagged, fire-and-forget pusher
# that mirrors StudioFire's current title to the stream CDN's metadata ingest
# (e.g. Icecast `updinfo`) so the public player shows song info. OFF by
Expand Down Expand Up @@ -209,6 +268,7 @@ def load_config(path: str | None = None) -> dict:
paths = cfg.get("paths", {})
core = cfg.get("core", {})
engine = cfg.get("engine", {})
telemetry = load_telemetry(core)
# Where a station's own data lives — resolved by the SAME module the engine
# uses (services/paths.py), because a disagreement here means the engine
# writes the journal and heartbeat where the core never looks.
Expand Down Expand Up @@ -242,8 +302,12 @@ def load_config(path: str | None = None) -> dict:
# dev/dry-run convenience: a GUI "restart everything" button. Set this
# to false on the ON-AIR PC so nobody can drop audio from the browser.
"allow_gui_restart": bool(core.get("allow_gui_restart", True)),
"ga_measurement_id": core.get("ga_measurement_id",
GA_MEASUREMENT_ID_DEFAULT),
"ga_measurement_id": telemetry["measurement_id"],
# Feature-usage telemetry is opt-in: both stay empty/false unless an
# operator turned it on. ``base.html`` keys the GA tag off the ID, so
# an untouched install renders no tracking script at all.
"telemetry_enabled": telemetry["enabled"],
"telemetry_install_id": telemetry["install_id"],
"precache_target_minutes": int(core.get("precache_target_minutes", 45)),
# how many tracks P1's queue itself is fed ahead of the play-head —
# deliberately shallow; precache_target_minutes (disk cache) is what
Expand Down
3 changes: 3 additions & 0 deletions services/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def state(conn, cfg: dict | None = None) -> dict:
"audio_device_guid": (cfg.get("audio_device_guid") or ""),
"np_file": db.get_setting(conn, "np_file") or "",
"stream_endpoint": db.get_setting(conn, "stream_endpoint") or "",
# Telemetry is opt-in and asked once, on the Done step. Nothing has
# ticked it yet at this point, so the checkbox starts unchecked.
"telemetry": bool((cfg or {}).get("telemetry_enabled")),
}
for key, _lbl in (("dir_station_ids", None), ("dir_psas", None),
("dir_jingles", None), ("dir_ads", None),
Expand Down
Loading
Loading