Skip to content

[Port to dtq-dev-93] Load Matomo only after cookie consent - #1751

Open
milanmajchrak wants to merge 1 commit into
dtq-dev-93from
93/fe-port-matomo-consent
Open

milanmajchrak wants to merge 1 commit into
dtq-dev-93from
93/fe-port-matomo-consent

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

References

Ports this dtq-dev PR:

On 7.6 the fix was a Klaro service and a new tracker. The v9 branch uses the DSpace 9 Matomo integration instead (MatomoService, ngx-matomo-client, the Orejime matomo app), so this PR changes MatomoService and keeps the rest.

Description

Matomo loads only after the visitor accepts it in the cookie settings, and nothing from a time without consent is sent later.

Instructions for Reviewers

List of changes in this PR:

  • MatomoService.init() no longer loads matomo.js when the config is known. The first consent does it.
  • A request processor, set before the first page view, empties every request queued without consent. Matomo never sends an empty request, so its consent queue cannot send them after a later accept.
  • Consent changes run as functions in Matomo's command queue, so they keep their order even before matomo.js has loaded. A queued setConsentGiven name would run first.
  • A new router interceptor matomoConsentInterceptor notes a page view queued without consent. On accept, only that current page is tracked again.
  • On revocation forgetConsentGiven runs, which deletes Matomo's cookies.
  • appendVisitorId adds the trackerId to a download link only while the visitor consents.
  • With info.enableCookieConsentPopup: false the current v9 code sends nothing: init() pushes forgetConsentGiven for visitors without a saved choice, so Matomo holds every request. This PR turns tracking on in that mode, without consent, as on 7.6.
  • The new consent specs in matomo.service.spec.ts run the queued commands through a small Matomo stand-in. Against the old MatomoService 4 of them fail: matomo.js is loaded before consent, and pages from before consent or from the declined period are sent after accept.

What visitors will notice:

  • No request to the Matomo host until they accept Matomo in the cookie notice or settings.
  • After accept, one page view for the current page. Pages visited before, or while Matomo was off, are not sent.
  • Download links get the Matomo trackerId only while the visitor consents.
  • Matomo also sends its own consent ping (ping=1) on a re-accept.
  • The page tracked on accept has itself as referrer, because ngx-matomo sets the referrer to the last page after each page view.

How to test:

  1. Configure Matomo (matomo.enabled, matomo.request.siteid, matomo.tracker.url) and build with npm run build:prod.
  2. Open the UI in a clean browser profile. DevTools shows no matomo.js and no matomo.php.
  3. Decline in the cookie notice and browse. Still no Matomo requests.
  4. Open cookie settings and enable Matomo. matomo.js loads and one page view for the current page is sent.
  5. Disable Matomo, click a file download link and browse to another page.
  6. Enable Matomo again. Only the current page (and ping=1) is sent, nothing from step 5.
  • npm run test -- --include=src/app/statistics/matomo.service.spec.ts

Codex review (gpt-6.2-sol, high): 2 findings, checked and not changed. Matomo writes no cookies before consent, so a page from before consent leaves no campaign data. A page view queued while the visitor consents is sent.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

🤖 Generated with Claude Code

Ports dtq-dev 7eddad8 (Matomo only after consent, no replay of declined activity).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant