Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1181 from navikt/feat-amplitude-søk
Browse files Browse the repository at this point in the history
Amplitude: Event for søk + Lagt til søk i header
  • Loading branch information
PerOlavM authored Aug 26, 2022
2 parents 68eb58a + 589e0e1 commit 138037b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/komponenter/header/header-regular/common/sok/Sok.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const Sok = (props: Props) => {
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
analyticsEvent({
eventName: 'søk',
destination: getSearchUrl(),
category: AnalyticsCategory.Header,
label: searchInput,
action: 'søk',
Expand Down Expand Up @@ -148,6 +150,13 @@ const fetchSearch = (props: FetchResult) => {
const url = `${APP_URL}/api/sok`;
setSubmitTrackerCookie();

analyticsEvent({
eventName: 'søk',
destination: url,
category: AnalyticsCategory.Header,
label: value,
action: 'søk-dynamisk',
});
fetch(`${url}?ord=${encodeURIComponent(value)}`)
.then((response) => {
if (response.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AppState } from 'store/reducers';
import { useDispatch } from 'react-redux';
import { lukkAlleDropdowns } from 'store/reducers/dropdown-toggle-duck';
import { Alert, Link } from '@navikt/ds-react';
import { logAmplitudeEvent } from 'utils/analytics/amplitude';

import './SokResultater.less';

Expand Down Expand Up @@ -63,7 +64,14 @@ export const SokResultater = (props: Props) => {
id={id}
className={'sokeresultat-lenke'}
href={item.href}
onClick={() => dispatch(lukkAlleDropdowns())}
onClick={() => {
dispatch(lukkAlleDropdowns());
logAmplitudeEvent('resultat-klikk', {
destinasjon: item.href,
sokeord: writtenInput.toLowerCase(),
treffnr: index + 1,
});
}}
>
<SokeforslagIngress
className="sok-resultat-listItem"
Expand Down
2 changes: 0 additions & 2 deletions src/utils/analytics/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ export const initAmplitude = () => {
saveEvents: false,
includeUtm: true,
includeReferrer: true,
platform: window.location.toString(),
});
}
};

export const logPageView = (params: Params, authState: InnloggingsstatusState) => {
logAmplitudeEvent('besøk', {
sidetittel: document.title,
platform: window.location.toString(),
innlogging: authState.data.securityLevel ?? false,
parametre: {
...params,
Expand Down
8 changes: 5 additions & 3 deletions src/utils/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type AnalyticsEventArgs = {
category: AnalyticsCategory;
action: string;
context?: MenuValue;
destination?: string;
label?: string;
komponent?: string;
lenkegruppe?: string;
Expand All @@ -31,14 +32,15 @@ export const initAnalytics = (params: Params) => {
};

export const analyticsEvent = (props: AnalyticsEventArgs) => {
const { context, eventName, category, action, label, komponent, lenkegruppe } = props;
const { context, eventName, destination, category, action, label, komponent, lenkegruppe } = props;
const actionFinal = `${context ? context + '/' : ''}${action}`;

logAmplitudeEvent(eventName || 'navigere', {
destinasjon: label,
destinasjon: destination || label,
søkeord: eventName === 'søk' ? label : undefined,
lenketekst: actionFinal,
kategori: category,
komponent,
komponent: komponent || action,
lenkegruppe,
});

Expand Down

0 comments on commit 138037b

Please sign in to comment.