diff --git a/src/komponenter/header/header-regular/common/sok/Sok.tsx b/src/komponenter/header/header-regular/common/sok/Sok.tsx index 1a3622133..5e30dad44 100644 --- a/src/komponenter/header/header-regular/common/sok/Sok.tsx +++ b/src/komponenter/header/header-regular/common/sok/Sok.tsx @@ -74,6 +74,8 @@ const Sok = (props: Props) => { const onSubmit = (e: React.FormEvent) => { e.preventDefault(); analyticsEvent({ + eventName: 'søk', + destination: getSearchUrl(), category: AnalyticsCategory.Header, label: searchInput, action: 'søk', @@ -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) { diff --git a/src/komponenter/header/header-regular/common/sok/sok-innhold/SokResultater.tsx b/src/komponenter/header/header-regular/common/sok/sok-innhold/SokResultater.tsx index 56230a774..47817f706 100644 --- a/src/komponenter/header/header-regular/common/sok/sok-innhold/SokResultater.tsx +++ b/src/komponenter/header/header-regular/common/sok/sok-innhold/SokResultater.tsx @@ -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'; @@ -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, + }); + }} > { saveEvents: false, includeUtm: true, includeReferrer: true, - platform: window.location.toString(), }); } }; @@ -20,7 +19,6 @@ export const initAmplitude = () => { export const logPageView = (params: Params, authState: InnloggingsstatusState) => { logAmplitudeEvent('besøk', { sidetittel: document.title, - platform: window.location.toString(), innlogging: authState.data.securityLevel ?? false, parametre: { ...params, diff --git a/src/utils/analytics/analytics.ts b/src/utils/analytics/analytics.ts index 5a512eff2..c37efc7fa 100644 --- a/src/utils/analytics/analytics.ts +++ b/src/utils/analytics/analytics.ts @@ -20,6 +20,7 @@ export type AnalyticsEventArgs = { category: AnalyticsCategory; action: string; context?: MenuValue; + destination?: string; label?: string; komponent?: string; lenkegruppe?: string; @@ -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, });