- Python 93.4%
- JavaScript 6.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| .gitignore | ||
| COPYING | ||
| COPYING.LESSER | ||
| MANIFEST.in | ||
| pyproject.toml | ||
| README.md | ||
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:
Plausible sets no cookie and keeps no query string but the campaign tags.<script defer data-domain="uvlhub.io" src="https://plausible.io/js/script.js" nonce="…"></script> - 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 loadsmatomo.jsfrom the Matomo server with the same nonce. The tracker ismatomo.phpnext to it.
What is never counted
- The excluded paths,
ANALYTICS_EXCLUDED_PATHS, and everything under them, segment by segment (/apiexcludes/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 sendsReferrer-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
- Select
analytics, an optional feature ofplataformain openhubs_spl, and pin it. It requires no other feature. - 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 toANALYTICS_EXCLUDED_PATHS. - 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.