Skip to content

TK-34: Record Matomo Analytics in Production - #70

Merged
burkkyy merged 4 commits into
mainfrom
tk-34/have-matomo-analytics-code-integrated-for-website-analytics
Sep 5, 2026
Merged

TK-34: Record Matomo Analytics in Production#70
burkkyy merged 4 commits into
mainfrom
tk-34/have-matomo-analytics-code-integrated-for-website-analytics

Conversation

@burkkyy

@burkkyy burkkyy commented Sep 5, 2026

Copy link
Copy Markdown
Member

Fixes https://yg-hpw.atlassian.net/browse/TK-34

Context

Matomo analytics were reported as not recording for the production Vault:

I am unable to access Matomo analytics. The Traditional Know Vault section shows no analytics.

The Matomo tracking code was already integrated (SPA page-view tracking wired through the router), but it never recorded in production for two independent reasons:

  1. The production build shipped with an empty tracker host — tracking is gated on VITE_MATOMO_HOST, which was not provided at build time, so the plugin no-opped.
  2. The app's Content Security Policy did not allow the external tracker, so the matomo.js script and the matomo.php beacons would have been blocked even once enabled.

Implementation

  1. Default the production tracker host to the Yukon Government analytics host so tracking is on in production without depending on a build-time environment variable (still overridable via VITE_MATOMO_HOST).
  2. Allowlist the analytics host in the Content Security Policy so the tracker script loads and page-view beacons are sent.
  3. Keep analytics disabled outside production (dev, UAT, and local runs remain off) so only the production Vault reports to Matomo site 115.

Screenshots

N/A - configuration changes only.

Testing Instructions

  1. Run the test suite via dev test.
  2. Boot the app via dev up.
  3. Log in to the app at http://localhost:3000.
  4. Note: analytics is production-only by design — local dev keeps Matomo disabled, so no beacons are sent while developing.
  5. Confirm the server allowlists the tracker: any API response's Content-Security-Policy header includes https://analytics.gov.yk.ca in both script-src and connect-src.
  6. To exercise the tracker locally, rebuild the web app with VITE_MATOMO_HOST=https://analytics.gov.yk.ca, load the app, navigate between pages, and verify in the browser Network tab that matomo.js loads and matomo.php requests fire with no CSP violations in the console.
  7. In production, navigate the Vault and verify page views appear under Matomo site 115.

Why? The Matomo integration was already present but never recorded: the
production build shipped with an empty tracker host, and the app's Content
Security Policy blocked the external tracker script and beacons.

Default the production tracker host to https://analytics.gov.yk.ca (still
overridable via VITE_MATOMO_HOST) and allowlist it in the script-src and
connect-src CSP directives. Non-production environments stay disabled.

See https://yg-hpw.atlassian.net/browse/TK-34
@burkkyy
burkkyy marked this pull request as ready for review September 5, 2026 04:07
@burkkyy
burkkyy merged commit ca6fa1a into main Sep 5, 2026
@burkkyy
burkkyy deleted the tk-34/have-matomo-analytics-code-integrated-for-website-analytics branch September 5, 2026 04:08
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