remove Matomo tracking
This commit is contained in:
parent
aa28e1ff21
commit
40def3b833
7 changed files with 25 additions and 385 deletions
14
README.md
14
README.md
|
|
@ -63,17 +63,3 @@ SITE=https://example.github.io BASE=/Incognito-Wiki npm run build
|
|||
Netlify reads `netlify.toml`, runs `npm run build`, and publishes `dist`. Configure `SITE` and `BASE` as environment values for the selected production hostname and path.
|
||||
|
||||
The removable workflow at `.github/workflows/deploy.yml` optionally deploys the GitHub mirror to Pages after a push to `main` or a manual dispatch. Set the public repository variables `SITE_URL` and `BASE_PATH` on GitHub. The workflow is GitHub-specific; Forgejo ignores it, and removing the workflow or `netlify.toml` does not affect local development or verification.
|
||||
|
||||
## Matomo analytics
|
||||
|
||||
The wiki uses self-hosted Matomo only after a visitor explicitly accepts analytics. The client is loaded from `https://analytics.msvincognito.nl/`, uses site ID `1`, and disables analytics cookies. Visitors can decline without losing functionality and can reopen **Privacy settings** to withdraw consent.
|
||||
|
||||
Before deploying analytics changes, the Matomo administrator must verify:
|
||||
|
||||
- IP anonymization is enabled;
|
||||
- raw logs and analytics reports use documented, proportionate retention periods;
|
||||
- administrator access is restricted and reviewed;
|
||||
- analytics data is not reused for advertising or cross-site profiling; and
|
||||
- the [MSV Incognito privacy policy](https://msvincognito.nl/privacy-policy) accurately states the controller, purpose, data categories, retention, withdrawal process, and data-subject rights.
|
||||
|
||||
The frontend consent gate is only one part of GDPR and ePrivacy compliance. Revisit the legal and server configuration when Matomo features or processing purposes change.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ const base = process.env.BASE || '/';
|
|||
const normalizedBase = base === '/'
|
||||
? ''
|
||||
: `/${base.replace(/^\/+|\/+$/g, '')}`;
|
||||
const matomoConsentScript = `${normalizedBase}/matomo-consent.js`;
|
||||
|
||||
export default defineConfig({
|
||||
site,
|
||||
|
|
@ -46,15 +45,6 @@ export default defineConfig({
|
|||
markdown: {
|
||||
processedDirs: ['./src/content/shared-courses/'],
|
||||
},
|
||||
head: [
|
||||
{
|
||||
tag: 'script',
|
||||
attrs: {
|
||||
src: matomoConsentScript,
|
||||
defer: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
social: [
|
||||
{
|
||||
icon: 'external',
|
||||
|
|
|
|||
|
|
@ -1,135 +0,0 @@
|
|||
(function initializeAnalyticsConsent(window, document) {
|
||||
'use strict';
|
||||
|
||||
var storageKey = 'incognito.analytics-consent.v1';
|
||||
var accepted = 'accepted';
|
||||
var declined = 'declined';
|
||||
var trackerOrigin = 'https://analytics.msvincognito.nl/';
|
||||
|
||||
if (window.__incognitoMatomoConsentController) return;
|
||||
window.__incognitoMatomoConsentController = true;
|
||||
|
||||
function readDecision() {
|
||||
try {
|
||||
var value = window.localStorage.getItem(storageKey);
|
||||
return value === accepted || value === declined ? value : null;
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function writeDecision(value) {
|
||||
try {
|
||||
window.localStorage.setItem(storageKey, value);
|
||||
} catch (_error) {
|
||||
// Consent applies to this page load only when browser storage is unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
function initializeMatomo() {
|
||||
var queue = window._paq = window._paq || [];
|
||||
if (window.__incognitoMatomoInitialized) return;
|
||||
|
||||
window.__incognitoMatomoInitialized = true;
|
||||
queue.push(['requireConsent']);
|
||||
queue.push(['disableCookies']);
|
||||
queue.push(['setConsentGiven']);
|
||||
queue.push(['setTrackerUrl', trackerOrigin + 'matomo.php']);
|
||||
queue.push(['setSiteId', '1']);
|
||||
queue.push(['trackPageView']);
|
||||
queue.push(['enableLinkTracking']);
|
||||
|
||||
var tracker = document.createElement('script');
|
||||
tracker.id = 'incognito-matomo-script';
|
||||
tracker.async = true;
|
||||
tracker.src = trackerOrigin + 'matomo.js';
|
||||
document.head.appendChild(tracker);
|
||||
}
|
||||
|
||||
function createButton(id, label) {
|
||||
var button = document.createElement('button');
|
||||
button.id = id;
|
||||
button.className = 'incognito-consent-action';
|
||||
button.type = 'button';
|
||||
button.textContent = label;
|
||||
return button;
|
||||
}
|
||||
|
||||
var banner = document.createElement('section');
|
||||
banner.id = 'incognito-analytics-consent';
|
||||
banner.setAttribute('role', 'dialog');
|
||||
banner.setAttribute('aria-labelledby', 'incognito-analytics-consent-title');
|
||||
banner.setAttribute('aria-describedby', 'incognito-analytics-consent-description');
|
||||
banner.innerHTML =
|
||||
'<div class="incognito-consent-copy">' +
|
||||
'<h2 id="incognito-analytics-consent-title">Privacy-friendly analytics</h2>' +
|
||||
'<p id="incognito-analytics-consent-description">MSV Incognito would like to use cookieless Matomo analytics to understand how the wiki is used. Nothing is sent to Matomo unless you accept. You can change your choice at any time.</p>' +
|
||||
'<a href="https://msvincognito.nl/privacy-policy">Read our privacy policy</a>' +
|
||||
'</div>';
|
||||
|
||||
var actions = document.createElement('div');
|
||||
actions.className = 'incognito-consent-actions';
|
||||
var acceptButton = createButton('incognito-analytics-accept', 'Accept analytics');
|
||||
var declineButton = createButton('incognito-analytics-decline', 'Decline');
|
||||
actions.appendChild(acceptButton);
|
||||
actions.appendChild(declineButton);
|
||||
banner.appendChild(actions);
|
||||
|
||||
var settingsButton = document.createElement('button');
|
||||
settingsButton.id = 'incognito-privacy-settings';
|
||||
settingsButton.type = 'button';
|
||||
settingsButton.textContent = 'Privacy settings';
|
||||
|
||||
function showBanner(moveFocus) {
|
||||
banner.hidden = false;
|
||||
settingsButton.hidden = true;
|
||||
if (moveFocus) acceptButton.focus();
|
||||
}
|
||||
|
||||
function hideBanner(restoreFocus) {
|
||||
banner.hidden = true;
|
||||
settingsButton.hidden = false;
|
||||
if (restoreFocus) settingsButton.focus();
|
||||
}
|
||||
|
||||
acceptButton.addEventListener('click', function acceptAnalytics() {
|
||||
if (banner.hidden) return;
|
||||
writeDecision(accepted);
|
||||
if (window.__incognitoMatomoInitialized) {
|
||||
window._paq.push(['setConsentGiven']);
|
||||
window._paq.push(['trackPageView']);
|
||||
} else {
|
||||
initializeMatomo();
|
||||
}
|
||||
hideBanner(true);
|
||||
});
|
||||
|
||||
declineButton.addEventListener('click', function declineAnalytics() {
|
||||
if (banner.hidden) return;
|
||||
writeDecision(declined);
|
||||
if (window._paq) {
|
||||
window._paq.push(['forgetConsentGiven']);
|
||||
window._paq.push(['deleteCookies']);
|
||||
}
|
||||
hideBanner(true);
|
||||
});
|
||||
|
||||
settingsButton.addEventListener('click', function openPrivacySettings() {
|
||||
showBanner(true);
|
||||
});
|
||||
|
||||
document.body.appendChild(banner);
|
||||
document.body.appendChild(settingsButton);
|
||||
|
||||
var decision = readDecision();
|
||||
if (decision === accepted) {
|
||||
banner.hidden = true;
|
||||
settingsButton.hidden = false;
|
||||
initializeMatomo();
|
||||
} else if (decision === declined) {
|
||||
banner.hidden = true;
|
||||
settingsButton.hidden = false;
|
||||
} else {
|
||||
showBanner(false);
|
||||
}
|
||||
})(window, document);
|
||||
|
|
@ -48,91 +48,6 @@
|
|||
color: var(--sl-color-gray-1);
|
||||
}
|
||||
|
||||
#incognito-analytics-consent {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
inset-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
|
||||
inset-block-end: max(1rem, env(safe-area-inset-bottom));
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
width: min(44rem, calc(100% - 2rem));
|
||||
margin-inline: auto;
|
||||
padding: 1.25rem;
|
||||
color: #fff;
|
||||
background: var(--incognito-navy);
|
||||
border: 1px solid color-mix(in srgb, var(--incognito-bright) 45%, transparent);
|
||||
border-radius: 0.75rem;
|
||||
box-shadow: 0 1rem 3rem rgb(0 0 0 / 30%);
|
||||
}
|
||||
|
||||
#incognito-analytics-consent[hidden],
|
||||
#incognito-privacy-settings[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.incognito-consent-copy h2 {
|
||||
margin: 0 0 0.5rem;
|
||||
color: inherit;
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
.incognito-consent-copy p {
|
||||
margin: 0 0 0.5rem;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.incognito-consent-copy a {
|
||||
color: var(--incognito-light);
|
||||
}
|
||||
|
||||
.incognito-consent-actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.incognito-consent-action,
|
||||
#incognito-privacy-settings {
|
||||
min-height: 2.75rem;
|
||||
border: 2px solid var(--incognito-light);
|
||||
border-radius: 0.5rem;
|
||||
color: var(--incognito-navy);
|
||||
background: var(--incognito-light);
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.incognito-consent-action:focus-visible,
|
||||
#incognito-privacy-settings:focus-visible {
|
||||
outline: 3px solid var(--incognito-pink);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
#incognito-privacy-settings {
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
inset-inline-end: max(1rem, env(safe-area-inset-right));
|
||||
inset-block-end: max(1rem, env(safe-area-inset-bottom));
|
||||
min-height: 2.25rem;
|
||||
padding-inline: 0.75rem;
|
||||
border-width: 1px;
|
||||
font-size: 0.8125rem;
|
||||
}
|
||||
|
||||
@media (min-width: 50rem) {
|
||||
#incognito-analytics-consent {
|
||||
grid-template-columns: minmax(0, 1fr) 18rem;
|
||||
align-items: end;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 30rem) {
|
||||
.incognito-consent-actions {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.programme-switch {
|
||||
padding: 0.625rem;
|
||||
margin: 0 0.5rem 0.75rem;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ async function collectCss(directory) {
|
|||
return chunks.join('\n');
|
||||
}
|
||||
|
||||
test('subpath production build includes local UI assets and focused programme navigation', async () => {
|
||||
test('subpath production build excludes analytics and includes focused programme navigation', async () => {
|
||||
const output = await mkdtemp(join(process.cwd(), '.matomo-build-'));
|
||||
try {
|
||||
await execFileAsync('node_modules/.bin/astro', ['build', '--outDir', output], {
|
||||
|
|
@ -33,12 +33,12 @@ test('subpath production build includes local UI assets and focused programme na
|
|||
|
||||
const html = await readFile(join(output, 'index.html'), 'utf8');
|
||||
const { document } = parseHTML(html);
|
||||
const scripts = document.querySelectorAll(
|
||||
'script[src="/Incognito-Wiki/matomo-consent.js"]',
|
||||
assert.equal(
|
||||
document.querySelector('script[src*="matomo"]'),
|
||||
null,
|
||||
'pages should not load Matomo or its consent controller',
|
||||
);
|
||||
assert.equal(scripts.length, 1, 'every page should load one base-aware local controller');
|
||||
assert.equal(scripts[0].hasAttribute('defer'), true);
|
||||
await access(join(output, 'matomo-consent.js'));
|
||||
await assert.rejects(access(join(output, 'matomo-consent.js')));
|
||||
|
||||
const computerScienceHtml = await readFile(join(output, 'computer-science/index.html'), 'utf8');
|
||||
const { document: computerScienceDocument } = parseHTML(computerScienceHtml);
|
||||
|
|
@ -67,9 +67,9 @@ test('subpath production build includes local UI assets and focused programme na
|
|||
assert.doesNotMatch(dataScienceSidebar.textContent, /Master DSDM/);
|
||||
|
||||
const css = await collectCss(output);
|
||||
assert.match(css, /#incognito-analytics-consent/);
|
||||
assert.match(css, /\.incognito-consent-action/);
|
||||
assert.match(css, /#incognito-privacy-settings/);
|
||||
assert.doesNotMatch(css, /#incognito-analytics-consent/);
|
||||
assert.doesNotMatch(css, /\.incognito-consent-action/);
|
||||
assert.doesNotMatch(css, /#incognito-privacy-settings/);
|
||||
} finally {
|
||||
await rm(output, { recursive: true, force: true });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,132 +0,0 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
import vm from 'node:vm';
|
||||
import { parseHTML } from 'linkedom';
|
||||
|
||||
const controllerSource = await readFile('public/matomo-consent.js', 'utf8').catch(() => '');
|
||||
const storageKey = 'incognito.analytics-consent.v1';
|
||||
|
||||
function queuedCommands(window) {
|
||||
return JSON.parse(JSON.stringify(window._paq));
|
||||
}
|
||||
|
||||
function runController({ decision, storageError = false } = {}) {
|
||||
const { document } = parseHTML('<!doctype html><html><head></head><body></body></html>');
|
||||
const values = new Map(decision ? [[storageKey, decision]] : []);
|
||||
const localStorage = {
|
||||
getItem(key) {
|
||||
if (storageError) throw new Error('storage unavailable');
|
||||
return values.get(key) ?? null;
|
||||
},
|
||||
setItem(key, value) {
|
||||
if (storageError) throw new Error('storage unavailable');
|
||||
values.set(key, value);
|
||||
},
|
||||
};
|
||||
const window = { localStorage };
|
||||
vm.runInNewContext(controllerSource, { window, document });
|
||||
return { window, document, values };
|
||||
}
|
||||
|
||||
test('first visit offers equal choices without initializing Matomo', () => {
|
||||
const { window, document } = runController();
|
||||
const banner = document.getElementById('incognito-analytics-consent');
|
||||
const accept = document.getElementById('incognito-analytics-accept');
|
||||
const decline = document.getElementById('incognito-analytics-decline');
|
||||
|
||||
assert.ok(banner, 'consent banner should exist');
|
||||
assert.ok(accept, 'accept button should exist');
|
||||
assert.ok(decline, 'decline button should exist');
|
||||
assert.equal(window._paq, undefined);
|
||||
assert.equal(document.querySelector('script[src*="analytics.msvincognito.nl"]'), null);
|
||||
assert.equal(banner.hidden, false);
|
||||
assert.equal(accept.className, decline.className);
|
||||
assert.equal(
|
||||
document.querySelector('#incognito-analytics-consent a').href,
|
||||
'https://msvincognito.nl/privacy-policy',
|
||||
);
|
||||
});
|
||||
|
||||
test('accepting persists consent and initializes cookieless Matomo once', () => {
|
||||
const { window, document, values } = runController();
|
||||
const accept = document.getElementById('incognito-analytics-accept');
|
||||
|
||||
assert.ok(accept, 'accept button should exist');
|
||||
accept.click();
|
||||
accept.click();
|
||||
|
||||
assert.equal(values.get(storageKey), 'accepted');
|
||||
assert.deepEqual(queuedCommands(window), [
|
||||
['requireConsent'],
|
||||
['disableCookies'],
|
||||
['setConsentGiven'],
|
||||
['setTrackerUrl', 'https://analytics.msvincognito.nl/matomo.php'],
|
||||
['setSiteId', '1'],
|
||||
['trackPageView'],
|
||||
['enableLinkTracking'],
|
||||
]);
|
||||
const scripts = document.querySelectorAll('#incognito-matomo-script');
|
||||
assert.equal(scripts.length, 1);
|
||||
assert.equal(scripts[0].src, 'https://analytics.msvincognito.nl/matomo.js');
|
||||
assert.equal(scripts[0].async, true);
|
||||
});
|
||||
|
||||
test('declining persists the choice without creating Matomo state', () => {
|
||||
const { window, document, values } = runController();
|
||||
document.getElementById('incognito-analytics-decline').click();
|
||||
|
||||
assert.equal(values.get(storageKey), 'declined');
|
||||
assert.equal(window._paq, undefined);
|
||||
assert.equal(document.getElementById('incognito-matomo-script'), null);
|
||||
assert.equal(document.getElementById('incognito-privacy-settings').hidden, false);
|
||||
});
|
||||
|
||||
test('remembered acceptance tracks on a later page load', () => {
|
||||
const { window, document } = runController({ decision: 'accepted' });
|
||||
|
||||
assert.ok(window._paq.some(([method]) => method === 'trackPageView'));
|
||||
assert.equal(document.querySelectorAll('#incognito-matomo-script').length, 1);
|
||||
assert.equal(document.getElementById('incognito-analytics-consent').hidden, true);
|
||||
});
|
||||
|
||||
test('remembered decline never initializes Matomo', () => {
|
||||
const { window, document } = runController({ decision: 'declined' });
|
||||
|
||||
assert.equal(window._paq, undefined);
|
||||
assert.equal(document.getElementById('incognito-matomo-script'), null);
|
||||
assert.equal(document.getElementById('incognito-privacy-settings').hidden, false);
|
||||
});
|
||||
|
||||
test('storage failure defaults to no tracking and keeps consent available', () => {
|
||||
const { window, document } = runController({ storageError: true });
|
||||
|
||||
assert.equal(window._paq, undefined);
|
||||
assert.equal(document.getElementById('incognito-analytics-consent').hidden, false);
|
||||
});
|
||||
|
||||
test('privacy settings allow an accepted visitor to withdraw consent', () => {
|
||||
const { window, document, values } = runController({ decision: 'accepted' });
|
||||
|
||||
document.getElementById('incognito-privacy-settings').click();
|
||||
document.getElementById('incognito-analytics-decline').click();
|
||||
|
||||
assert.equal(values.get(storageKey), 'declined');
|
||||
assert.deepEqual(queuedCommands(window).slice(-2), [
|
||||
['forgetConsentGiven'],
|
||||
['deleteCookies'],
|
||||
]);
|
||||
|
||||
const later = runController({ decision: values.get(storageKey) });
|
||||
assert.equal(later.window._paq, undefined);
|
||||
assert.equal(later.document.getElementById('incognito-matomo-script'), null);
|
||||
});
|
||||
|
||||
test('running the local controller twice does not duplicate UI or tracking', () => {
|
||||
const state = runController({ decision: 'accepted' });
|
||||
vm.runInNewContext(controllerSource, { window: state.window, document: state.document });
|
||||
|
||||
assert.equal(state.document.querySelectorAll('#incognito-analytics-consent').length, 1);
|
||||
assert.equal(state.document.querySelectorAll('#incognito-matomo-script').length, 1);
|
||||
assert.equal(state.window._paq.filter(([method]) => method === 'trackPageView').length, 1);
|
||||
});
|
||||
16
tests/no-matomo.test.mjs
Normal file
16
tests/no-matomo.test.mjs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { access, readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
test('the wiki contains no active Matomo tracking integration', async () => {
|
||||
const [config, css, readme] = await Promise.all([
|
||||
readFile('astro.config.mjs', 'utf8'),
|
||||
readFile('src/styles/incognito.css', 'utf8'),
|
||||
readFile('README.md', 'utf8'),
|
||||
]);
|
||||
|
||||
assert.doesNotMatch(config, /matomo/i);
|
||||
assert.doesNotMatch(css, /incognito-(?:analytics|consent|privacy-settings)/i);
|
||||
assert.doesNotMatch(readme, /matomo/i);
|
||||
await assert.rejects(access('public/matomo-consent.js'));
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue