Cookieless visit analytics (Plausible or Matomo) for a hub, without a consent banner
  • Python 93.4%
  • JavaScript 6.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-01 11:22:46 +01:00
src Ask the page's Content-Security-Policy for the provider's origin 2026-10-31 19:20:05 +01:00
.gitignore feat: scaffold splent_feature_analytics with splent feature:create 2026-10-25 00:35:19 +02:00
COPYING feat: scaffold splent_feature_analytics with splent feature:create 2026-10-25 00:35:19 +02:00
COPYING.LESSER feat: scaffold splent_feature_analytics with splent feature:create 2026-10-25 00:35:19 +02:00
MANIFEST.in feat: scaffold splent_feature_analytics with splent feature:create 2026-10-25 00:35:19 +02:00
pyproject.toml chore: release splent_io/splent_feature_analytics to v0.2.0 2026-11-01 11:22:46 +01:00
README.md docs: the parameters' types and binds, and the default excluded paths 2026-10-25 16:24:36 +01:00

splent_feature_analytics

Visit counts for a SPLENT product without cookies, so without a consent banner (decision D11): Plausible or Matomo, cloud or self-hosted. Optional in the line and off by default: until the deployment gives the script and the site, nothing is loaded.

What a page gets

The tag goes at the end of every page of both shells, in the layout.scripts slot, with the request's Content-Security-Policy nonce (csp_nonce()), so a policy that names the nonce allows it and no inline script is needed.

  • plausible: the provider's script, with the site's domain:
    <script defer data-domain="uvlhub.io" src="https://plausible.io/js/script.js" nonce="…"></script>
    
    Plausible sets no cookie and keeps no query string but the campaign tags.
  • matomo: this feature's own assets/js/matomo.js, which reads the server and the site from its data attributes, tells Matomo to set no cookie (disableCookies) and to record the page and the referrer without their query strings, and then loads matomo.js from the Matomo server with the same nonce. The tracker is matomo.php next to it.

What is never counted

  • The excluded paths, ANALYTICS_EXCLUDED_PATHS, and everything under them, segment by segment (/api excludes /api/v1/datasets, not /apidocs). By default: the administration, the account pages, signing in, up and out, the reset and confirmation links, the developer pages, the API, the ORCID and GitHub returns, and the acceptance of the legal texts.
  • The pages of a signed-in account, unless ANALYTICS_SIGNED_IN: their addresses are about the account.
  • Every page that holds a token (ID-14), whatever its path: a reset or confirmation link, the page that shows a new API token, the return from a provider. Those go through auth's keep_token_private, which sends Referrer-Policy: no-referrer; a response that sends no Referer to anybody has the tag taken out before it leaves. The page carries no script of another site, and its address reaches no counter, even one served from the site's own domain.

The Content-Security-Policy

A product that sends one (SPLENT_CONTENT_SECURITY_POLICY) names the provider's host in script-src and connect-src (and img-src for Matomo's fallback), or uses the nonce with 'strict-dynamic'. The feature says at start when the policy would block the script.

With splent_feature_legal, the provider is listed in the privacy notice as a third party, with its host; no cookie is declared, since none is set.

Settings

Each is a typed parameter in [tool.splent.config_schema], so product:validate checks a product's value against it. The two of deploy bind are left to each deployment's .env; the rest are decided when the product is derived.

Variable Type Bind Default
ANALYTICS_PROVIDER enum derivation plausible plausible or matomo
ANALYTICS_SCRIPT_URL url deploy Plausible's script.js, or the address of matomo.js on the Matomo server. Empty loads nothing
ANALYTICS_SITE_ID str deploy The domain registered in Plausible, or the site's number in Matomo. Matches [A-Za-z0-9.:_-]{1,253}
ANALYTICS_EXCLUDED_PATHS list derivation the sensitive routes Paths never counted, with everything under them. Each matches /.*
ANALYTICS_SIGNED_IN bool derivation false Whether the pages of a signed-in account are counted

The default ANALYTICS_EXCLUDED_PATHS is /admin, /account, /login, /logout, /signup, /reset, /confirmemail, /confirm_email_change, /confirm_user, /developer, /api, /orcid, /github and /legal/accept. A product that sets it replaces the list, so it keeps these and adds its own.

At start the feature refuses a Matomo site that is not a number, and in production a script over plain http, or a script without a site (or the reverse); elsewhere the last is a warning and nothing is loaded.

Enable it in a product

  1. Select analytics, an optional feature of plataforma in openhubs_spl, and pin it. It requires no other feature.
  2. Choose the provider in the product's [tool.splent.config] if it is not Plausible, and add any path of the product's own that must not be counted to ANALYTICS_EXCLUDED_PATHS.
  3. In the deployment's .env:
    ANALYTICS_SCRIPT_URL=https://plausible.io/js/script.js
    ANALYTICS_SITE_ID=uvlhub.io
    

Develop

splent feature:test analytics --neutral
splent feature:contract analytics --write

No test calls Plausible or Matomo: they check the tag the pages carry.