diff --git a/charts/Feature.yaml b/charts/Feature.yaml index c917e7ee9..72fd5df63 100644 --- a/charts/Feature.yaml +++ b/charts/Feature.yaml @@ -43,3 +43,18 @@ values: displayName: Number of replicas config: type: int + tracking.enabled: + displayName: Enable analytics tracking + description: Enable Umami/Innblikk tracking via the ResearchOps sporing script + config: + type: bool + tracking.websiteId: + displayName: Tracking website ID + description: The Umami/Innblikk website UUID for this tenant + config: + type: string + tracking.dev: + displayName: Use dev tracking proxy + description: Use the dev sporing script and proxy endpoint instead of production + config: + type: bool diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml index 8897814e2..4ec51299a 100644 --- a/charts/templates/deployment.yaml +++ b/charts/templates/deployment.yaml @@ -23,6 +23,12 @@ spec: value: '{{ .Values.fasit.tenant.name }}' - name: 'GITHUB_ORGANIZATION' value: '{{ .Values.gitHub.organization }}' + - name: 'TRACKING_ENABLED' + value: '{{ .Values.tracking.enabled }}' + - name: 'TRACKING_WEBSITE_ID' + value: '{{ .Values.tracking.websiteId }}' + - name: 'TRACKING_DEV' + value: '{{ .Values.tracking.dev }}' # - name: 'OTEL_TRACES_EXPORTER' # value: 'otlp' # - name: 'OTEL_METRICS_EXPORTER' diff --git a/charts/values.yaml b/charts/values.yaml index b0121e6ce..2ed00f401 100644 --- a/charts/values.yaml +++ b/charts/values.yaml @@ -21,3 +21,8 @@ resources: memory: 512Mi replicaCount: 2 + +tracking: + enabled: false + websiteId: "" + dev: false diff --git a/docs/umami-integration.md b/docs/umami-integration.md new file mode 100644 index 000000000..bddd89959 --- /dev/null +++ b/docs/umami-integration.md @@ -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 ` diff --git a/src/routes/team/[team]/[env]/secret/[secret]/ViewSecretModal.svelte b/src/routes/team/[team]/[env]/secret/[secret]/ViewSecretModal.svelte index ae1e03ea9..b297a147c 100644 --- a/src/routes/team/[team]/[env]/secret/[secret]/ViewSecretModal.svelte +++ b/src/routes/team/[team]/[env]/secret/[secret]/ViewSecretModal.svelte @@ -6,6 +6,7 @@ import { PadlockLockedIcon } from '@nais/ds-svelte-community/icons'; import type { ValueEncoding$options } from '$houdini'; + import { trackEvent } from '$lib/tracking'; interface SecretValue { name: string; @@ -55,6 +56,7 @@ isSubmitting = false; if (!$revealSecrets.errors && $revealSecrets.data?.viewSecretValues?.values) { + trackEvent('reveal-secret'); onSuccess($revealSecrets.data.viewSecretValues.values); handleClose(); } diff --git a/src/routes/team/[team]/settings/confirm_delete/+page.svelte b/src/routes/team/[team]/settings/confirm_delete/+page.svelte index 2c989efc8..18aa8058c 100644 --- a/src/routes/team/[team]/settings/confirm_delete/+page.svelte +++ b/src/routes/team/[team]/settings/confirm_delete/+page.svelte @@ -6,6 +6,7 @@ type ConfirmTeamDeletion$result, type QueryResult } from '$houdini'; + import { trackEvent } from '$lib/tracking'; import GraphErrors from '$lib/ui/GraphErrors.svelte'; import Time from '$lib/ui/Time.svelte'; import { Alert, BodyLong, Button, Modal } from '@nais/ds-svelte-community'; @@ -77,6 +78,15 @@ key: key.key, team: key.team.slug }); + if (deleteTeamResp.errors) { + deleteTeamLoading = false; + return; + } + if (!deleteTeamResp.data?.confirmTeamDeletion.deletionStarted) { + deleteTeamLoading = false; + return; + } + trackEvent('delete-team'); goto('/team/' + key.team.slug, { replaceState: true }); }}>Confirm