-
Notifications
You must be signed in to change notification settings - Fork 1
feat: integrate Umami/Innblikk tracking via ResearchOps sporing script #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rbjornstad
wants to merge
6
commits into
main
Choose a base branch
from
feat/umami-tracking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
28e40da
feat: integrate Umami/Innblikk tracking via ResearchOps sporing script
rbjornstad e78f880
feat: use route IDs instead of resolved URLs for tracking
rbjornstad 799daa5
fix: address review comments
rbjornstad ab2942c
fix: drop events without route ID, add tracking.dev to Feature.yaml, …
rbjornstad c4c20eb
refactor: remove unnecessary type annotations and eslint-disable in b…
rbjornstad 16aa91c
fix: pageTypeFromPath for team sub-pages, allow custom events without…
rbjornstad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,8 @@ resources: | |
| memory: 512Mi | ||
|
|
||
| replicaCount: 2 | ||
|
|
||
| tracking: | ||
| enabled: false | ||
| websiteId: "" | ||
| dev: false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Plan: Integrate Umami/Sporing Analytics | ||
|
|
||
| ## Summary | ||
|
|
||
| Add NAV's ResearchOps "sporing" tracking script to console-frontend. This provides privacy-first analytics (no cookies, GDPR compliant) with automatic page view tracking and custom event tracking for key user actions. Data flows through NAV's event proxy to BigQuery. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. Request website registration in Slack `#researchops` — provide: app name ("Console"), domain, team name | ||
| 2. Get tracking codes from `innblikk.ansatt.nav.no/sporingskoder` (prod) and `innblikk.ansatt.dev.nav.no/sporingskoder` (dev) | ||
|
|
||
| ## Steps | ||
|
|
||
| ### Phase 1: Chart & Server Configuration | ||
|
|
||
| 1. **Add tracking flag to Helm chart** — New values in `charts/Feature.yaml` and `charts/values.yaml`: | ||
| - `tracking.enabled` (boolean, default `false`) — opt-in per tenant | ||
| - `tracking.websiteId` (string) — the Umami/Innblikk website UUID | ||
| - Add env vars `TRACKING_ENABLED` and `TRACKING_WEBSITE_ID` to `charts/templates/deployment.yaml` | ||
|
|
||
| 2. **Pass tracking config to client via layout** — In `src/hooks.server.ts`, read `TRACKING_ENABLED` and `TRACKING_WEBSITE_ID` from env, expose via `event.locals`. In `src/routes/+layout.server.ts`, pass to page data. This follows the existing pattern for `tenantName` and `githubOrganization`. | ||
|
|
||
| ### Phase 2: Script Integration | ||
|
|
||
| 3. **Conditionally inject tracking script** — In `src/routes/+layout.svelte` `onMount`, dynamically create and append the `<script>` tag when `data.trackingEnabled` is true. Uses `sporing-dev.js` when `data.trackingDev` is true, otherwise production `sporing.js`. | ||
|
|
||
| 4. **Add `beforeSend` function** — Assigned to `window.beforeSend` in `onMount`. Replaces resolved URLs with SvelteKit route IDs (e.g. `/team/[team]/secrets`) for aggregate page analytics. Route ID is kept in sync via `afterNavigate`. | ||
|
|
||
| 5. **Add TypeScript type declarations in `src/app.d.ts`** — Declare `window.sporing` with `track()` and `identify()` methods so custom event calls are type-safe. Update `App.Locals` and layout data types for tracking config. | ||
|
|
||
| ### Phase 3: Custom Event Tracking | ||
|
|
||
| 6. **Create a tracking utility module `src/lib/tracking.ts`** — Thin wrapper around `window.sporing.track()` that: | ||
| - Checks if `window.sporing` exists (guards against script not loaded, local dev, tests) | ||
| - Exposes typed `trackEvent(name: string, data?: Record<string, string | number | boolean>)` function | ||
| - No-ops gracefully if tracking unavailable | ||
|
|
||
| 7. **Add event tracking to key user actions** — Import and call `trackEvent()` after successful actions. Page context (route ID) is automatically included via `beforeSend`. Start with Tier 1 (highest insight value): | ||
| - **Favourites**: `favorite-add`, `favorite-remove`, `favorite-reorder`, `favorite-click` — in `src/lib/ui/AddToFavorites.svelte`, `src/lib/domain/list-items/FavoritesListItem.svelte`, `src/routes/FavoritesList.svelte` | ||
| - **Team lifecycle**: `delete-team` — in `src/routes/team/[team]/settings/confirm_delete/+page.svelte` | ||
| - **App lifecycle**: `restart-app`, `stop-app`, `delete-app` — in `src/routes/team/[team]/[env]/app/[app]/AppActions.svelte`, `src/routes/team/[team]/[env]/app/[app]/delete/+page.svelte` | ||
| - **Secret access**: `reveal-secret` — in `src/routes/team/[team]/[env]/secret/[secret]/ViewSecretModal.svelte` | ||
| - **Job triggers**: `trigger-job` — in `src/routes/team/[team]/[env]/job/[job]/JobActions.svelte` | ||
| - **Vulnerability mgmt**: `suppress-vulnerability` — in `src/lib/domain/vulnerability/SuppressFinding.svelte` | ||
|
|
||
| Events carry only the event name. No custom payload data, no user identifiers, no resource names. Page context (route ID pattern) is attached automatically by `beforeSend`. | ||
|
|
||
| ### Phase 4: Development & Testing Setup | ||
|
|
||
| 8. **Dev script variant** — In `onMount`, conditionally load `sporing-dev.js` (proxy: `reops-event-proxy.ekstern.dev.nav.no`) for non-production. Controlled by `TRACKING_DEV` env var. | ||
|
|
||
| 9. **Disable tracking in tests** — Set `localStorage.setItem('sporing.disabled', '1')` in E2E/Playwright setup. | ||
|
|
||
| ## Decisions | ||
|
|
||
| - **Multi-tenant**: Tracking is opt-in per tenant via Helm chart flag (`tracking.enabled`). Disabled by default — only enabled for NAV where no consent is required | ||
| - **No consent UI**: Console for NAV is an internal ansatte tool — cookie consent not required per ResearchOps guidance | ||
| - **No user identification**: Fully anonymous tracking, no `sporing.identify()` calls | ||
| - **Route IDs sent instead of resolved URLs**: `beforeSend` replaces the page URL with the SvelteKit route ID (e.g., `/team/[team]/[env]/app/[app]`), so no team/app/env slugs are ever transmitted. Events are dropped if no route ID is available. | ||
| - **Query params never sent**: Since only route IDs are transmitted, query parameters are inherently excluded | ||
| - **No CSP changes needed currently**: No CSP headers are configured; if CSP is added later, allowlist `cdn.nav.no` (script-src) and `reops-event-proxy.nav.no` + `reops-event-proxy.ekstern.dev.nav.no` (connect-src) | ||
| - **Server-side mutations**: For mutations in `+page.server.ts` (form actions), tracking must happen client-side after the form action succeeds | ||
|
|
||
| ## References | ||
|
|
||
| - [ResearchOps sporing docs](https://reops-docs.ansatt.dev.nav.no/innsamling/sporingsskript/) | ||
| - [Getting started guide](https://reops-docs.ansatt.dev.nav.no/guider/kom-i-gang-med-sporing/) | ||
| - Dashboard: `innblikk.ansatt.nav.no` (prod) / `innblikk.ansatt.dev.nav.no` (dev) | ||
| - BigQuery: `team-researchops-prod-01d6.umami_views.event` | ||
| - Slack: `#researchops` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { browser } from '$app/environment'; | ||
|
|
||
| export function trackEvent(name: string, data?: Record<string, string | number | boolean>): void { | ||
| if (!browser || !window.sporing) return; | ||
| if (data) { | ||
| window.sporing.track(name, data); | ||
| } else { | ||
| window.sporing.track(name); | ||
| } | ||
| } | ||
|
rbjornstad marked this conversation as resolved.
rbjornstad marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.