Skip to content

Commit

Permalink
Legger til mulighet for å skru av logging til Amplitude og Umami
Browse files Browse the repository at this point in the history
  • Loading branch information
Zandra7 committed Jan 15, 2025
1 parent 06060c2 commit 9809630
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .nais/nais.demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
- name: FARO_URL
value: {{faro_url}}
- name: RUNTIME_ENVIRONMENT
value: {{RUNTIME_ENVIRONMENT}}
value: {{runtime_environment}}
- name: SANITY_DATASETT
value: {{sanity_datasett}}
accessPolicy:
Expand Down
2 changes: 2 additions & 0 deletions .nais/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ spec:
value: {{sanity_datasett}}
- name: UMAMI_ID
value: {{umami_id}}
- name: SKAL_LOGGE
value: skal_logge
accessPolicy:
outbound:
external:
Expand Down
3 changes: 2 additions & 1 deletion .nais/vars-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dekorator:
url: https://dekoratoren.dev.nav.no/
env: dev
faro_url: "https://telemetry.ekstern.dev.nav.no/collect"
RUNTIME_ENVIRONMENT: "demo"
runtime_environment: "demo"
sanity_datasett: "production"
umami_id: "24bd3b5d-f1e6-446c-a551-0bf556592157"
skal_logge: "true"
1 change: 1 addition & 0 deletions .nais/vars-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ umami_id: "ccee3ffe-f3c3-4ef6-8e01-742756847782"
replicas:
min: 2
max: 2
skal_logge: "true"

1 change: 1 addition & 0 deletions .nais/vars-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ umami_id: ""
replicas:
min: 2
max: 2
skal_logge: "true"
16 changes: 10 additions & 6 deletions app/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ export function useAnalytics() {

const trackEvent = useCallback(
<T extends object>(event: string, props: T = {} as T) => {
if (isLocalOrDemo) {
if (getEnv("SKAL_LOGGE") !== "true") return;

if (umami && isLocalOrDemo) {
umami(event, {
skjemanavn,
språk,
...props,
});
}

amplitude(event, {
skjemanavn,
språk,
...props,
});
if (amplitude) {
amplitude(event, {
skjemanavn,
språk,
...props,
});
}
},
[umami, amplitude, språk],
);
Expand Down
1 change: 1 addition & 0 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
SANITY_DATASETT: process.env.SANITY_DATASETT,
GITHUB_SHA: process.env.GITHUB_SHA,
UMAMI_ID: process.env.UMAMI_ID,
SKAL_LOGGE: process.env.SKAL_LOGGE,
},
fragments,
};
Expand Down
1 change: 1 addition & 0 deletions app/utils/env.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface IEnv {
RUNTIME_ENVIRONMENT: string;
SANITY_DATASETT: string;
UMAMI_ID: string;
SKAL_LOGGE: string;
}

export function getEnv(value: keyof IEnv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ vi.mock("~/hooks/useLocale", () => ({
useLocale: () => ({ locale: "no" }),
}));

const env: { [key: string]: string } = {
UMAMI_ID: "",
SKAL_LOGGE: "true",
};

vi.mock("~/utils/env.utils", () => ({
getEnv: (name: string) => env[name],
isLocalOrDemo: false,
}));

describe("useAnalytics", () => {
const skjemanavn = "dagpenger-rapportering";
const språk = "no";
Expand Down

0 comments on commit 9809630

Please sign in to comment.