Skip to content

Commit

Permalink
IS-2828: Add amplitude logging for sok
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikdahlen committed Nov 29, 2024
1 parent a947db4 commit 3663b71
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/components/sokperson/SokPerson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SokPersonResultat from '@/components/sokperson/SokPersonResultat';
import { MagnifyingGlassIcon } from '@navikt/aksel-icons';
import { isNumeric, removePunctuation } from '@/utils/stringUtil';
import { parseDateString } from '@/utils/dateUtils';
import * as Amplitude from '@/utils/amplitude';

const texts = {
header: 'Søk etter sykmeldt',
Expand All @@ -28,6 +29,27 @@ const texts = {
error: 'Noe gikk galt under søket. Vennligst prøv igjen.',
};

function logSokPersonEvent() {
Amplitude.logEvent({
type: Amplitude.EventType.ButtonClick,
data: {
url: window.location.href,
tekst: 'Søk etter sykmeldt',
},
});
}

function logSokPersonResults(amount: number) {
Amplitude.logEvent({
type: Amplitude.EventType.AmountDisplayed,
data: {
url: window.location.href,
antall: amount,
handling: 'Søk etter sykmeldt - resultater',
},
});
}

export default function SokPerson() {
const [nameInitials, setNameInitials] = useState<string>('');
const [birthdate, setBirthdate] = useState<string>('');
Expand Down Expand Up @@ -61,7 +83,10 @@ export default function SokPerson() {
initials: nameInitials.toLowerCase(),
birthdate: parsedBirthdate,
};
mutate(requestDTO);
mutate(requestDTO, {
onSuccess: (data) => logSokPersonResults(data.length),
onSettled: () => logSokPersonEvent(),
});
} else {
setIsFormError(true);
}
Expand Down
13 changes: 12 additions & 1 deletion src/utils/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum EventType {
OptionSelected = 'alternativ valgt',
ButtonClick = 'knapp trykket',
SortingColumn = 'kolonne sortert på',
AmountDisplayed = 'antall vist',
}

type EventPageView = {
Expand Down Expand Up @@ -56,12 +57,22 @@ type EventSortingColumn = {
};
};

type EventAmountDisplayed = {
type: EventType.AmountDisplayed;
data: {
url: string;
antall: number;
handling: string;
};
};

type Event =
| EventPageView
| Navigation
| OptionSelected
| EventButtonClick
| EventSortingColumn;
| EventSortingColumn
| EventAmountDisplayed;

export const logEvent = (event: Event) =>
amplitude.track(event.type, { ...event.data });
Expand Down

0 comments on commit 3663b71

Please sign in to comment.