Skip to content

Commit 1cd3a93

Browse files
committed
chore: add cookie consent page, fix matomo tracking
1 parent 47cedee commit 1cd3a93

8 files changed

Lines changed: 36 additions & 58 deletions

File tree

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export enum ROUTES {
2323
ACCESSIBILITY_STATEMENT = '/accessibility-statement',
2424
ATTENDANCE_LIST = '/registrations/:registrationId/attendance-list',
2525
CALLBACK = '/callback',
26+
COOKIES = '/cookies',
2627
CREATE_EVENT = '/events/create',
2728
CREATE_IMAGE = '/administration/images/create',
2829
CREATE_KEYWORD = '/administration/keywords/create',

src/domain/app/footer/Footer.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ const Footer: React.FC = () => {
148148
onClick={goToPage(getLocalePath(ROUTES.ACCESSIBILITY_STATEMENT))}
149149
label={t('navigation.tabs.accessibilityStatement')}
150150
/>
151+
<HdsFooter.Link
152+
href={getLocalePath(ROUTES.COOKIES)}
153+
onClick={goToPage(getLocalePath(ROUTES.COOKIES))}
154+
label={t('navigation.tabs.cookies')}
155+
/>
151156
</HdsFooter.Utilities>
152157
<HdsFooter.Base
153158
copyrightHolder={t('footer.copyrightHolder')}

src/domain/app/hooks/useCookieConsentSettings.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
import { CookieConsentReactProps } from 'hds-react';
1+
import { CookieConsentChangeEvent, CookieConsentReactProps } from 'hds-react';
22

33
import { PAGE_HEADER_ID } from '../../../constants';
44
import useLocale from '../../../hooks/useLocale';
55
import siteSettings from './data/siteSettings.json';
66

7+
export enum COOKIE_CONSENT_GROUP {
8+
Tunnistamo = 'tunnistamo',
9+
UserInputs = 'userInputs',
10+
Shared = 'shared',
11+
Statistics = 'statistics',
12+
}
13+
714
const useCookieConsentSettings = () => {
815
const locale = useLocale();
916

1017
const cookieConsentProps: CookieConsentReactProps = {
11-
// eslint-disable-next-line @typescript-eslint/no-empty-function
12-
onChange: () => {},
18+
onChange: (changeEvent: CookieConsentChangeEvent) => {
19+
const { acceptedGroups } = changeEvent;
20+
21+
const hasStatisticsConsent =
22+
acceptedGroups.indexOf(COOKIE_CONSENT_GROUP.Statistics) > -1;
23+
24+
if (hasStatisticsConsent) {
25+
// start tracking
26+
window._paq.push(['setConsentGiven']);
27+
window._paq.push(['setCookieConsentGiven']);
28+
} else {
29+
// tell matomo to forget conset
30+
window._paq.push(['forgetConsentGiven']);
31+
}
32+
},
1333
siteSettings: siteSettings,
1434
options: { focusTargetSelector: `#${PAGE_HEADER_ID}`, language: locale },
1535
};

src/domain/app/i18n/en.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@
9999
"clearUsers": "Clear selected users",
100100
"toggleButtonAriaLabel": "Menu"
101101
},
102-
"cookieConsent": {
103-
"eventForm": {
104-
"description": "The cookie required to save the event form data",
105-
"name": "Event form cookie"
106-
},
107-
"expiration": {
108-
"session": "Session"
109-
},
110-
"registrationForm": {
111-
"description": "The cookie required to save the registration form data",
112-
"name": "Registration form cookie"
113-
},
114-
"signupForm": {
115-
"description": "The cookie required to save the signup form data",
116-
"name": "Signup form cookie"
117-
},
118-
"siteName": "Linked Events"
119-
},
120102
"dateSelector": {
121103
"buttonToggle": "Choose dates",
122104
"placeholderEndDate": "Ends d.m.yyyy",
@@ -1638,6 +1620,7 @@
16381620
"accessibilityStatement": "Accessibility Statement",
16391621
"admin": "Admin",
16401622
"events": "My events",
1623+
"cookies": "Cookie settings",
16411624
"help": "Support",
16421625
"registrations": "Registration",
16431626
"dataProtection": "Data Protection",

src/domain/app/i18n/fi.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@
9999
"clearUsers": "Tyhjennä valitut käyttäjät",
100100
"toggleButtonAriaLabel": "Valikko"
101101
},
102-
"cookieConsent": {
103-
"eventForm": {
104-
"description": "Tapahtumalomakkeen tietojen säilymiseksi vaadittu eväste",
105-
"name": "Tapahtumalomakkeen eväste"
106-
},
107-
"expiration": {
108-
"session": "Istunto"
109-
},
110-
"registrationForm": {
111-
"description": "Ilmoittautumislomakkeen tietojen säilymiseksi vaadittu eväste",
112-
"name": "Ilmoittautumislomakkeen eväste"
113-
},
114-
"signupForm": {
115-
"description": "Osallistumislomakkeen tietojen säilymiseksi vaadittu eväste",
116-
"name": "Osallistumislomakkeen eväste"
117-
},
118-
"siteName": "Linked Events"
119-
},
120102
"dateSelector": {
121103
"buttonToggle": "Valitse päivämäärät",
122104
"placeholderEndDate": "Loppuu p.k.vvvv",
@@ -1638,6 +1620,7 @@
16381620
"accessibilityStatement": "Saavutettavuusseloste",
16391621
"admin": "Hallinta",
16401622
"events": "Omat tapahtumat",
1623+
"cookies": "Evästeasetukset",
16411624
"help": "Tuki",
16421625
"registrations": "Ilmoittautuminen",
16431626
"dataProtection": "Tietosuoja",

src/domain/app/i18n/sv.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@
9999
"clearUsers": "Ta bort valda användare",
100100
"toggleButtonAriaLabel": "Menyn"
101101
},
102-
"cookieConsent": {
103-
"eventForm": {
104-
"description": "Den cookie som krävs för att spara data från evenemangsformuläret",
105-
"name": "Cookie för evenemangsformulär"
106-
},
107-
"expiration": {
108-
"session": "Session"
109-
},
110-
"registrationForm": {
111-
"description": "Den cookie som krävs för att spara uppgifterna i registreringsformuläret",
112-
"name": "Cookie för registreringsformulär"
113-
},
114-
"signupForm": {
115-
"description": "Den cookie som krävs för att spara uppgifterna i deltagaresformuläret",
116-
"name": "Cookie för deltagaresformulär"
117-
},
118-
"siteName": "Linked Events"
119-
},
120102
"dateSelector": {
121103
"buttonToggle": "Välj datum",
122104
"placeholderEndDate": "Avslutar d.m.åååå",
@@ -1638,6 +1620,7 @@
16381620
"accessibilityStatement": "Tillgänglighetsutlåtande",
16391621
"admin": "Admin",
16401622
"events": "Mina evenemangen",
1623+
"cookies": "Kakinställningar",
16411624
"help": "Stöd",
16421625
"registrations": "Registrering",
16431626
"dataProtection": "Dataskydd",

src/domain/app/layout/pageWrapper/PageWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useLocation } from 'react-router';
77

88
import useMatomo from '../../../../common/components/matomoTracker/hooks/useMatomo';
99
import upperCaseFirstLetter from '../../../../utils/upperCaseFirstLetter';
10+
import { COOKIE_CONSENT_GROUP } from '../../hooks/useCookieConsentSettings';
1011
import styles from './pageWrapper.module.scss';
1112

1213
export interface PageWrapperProps {
@@ -35,7 +36,7 @@ const PageWrapper: React.FC<React.PropsWithChildren<PageWrapperProps>> = ({
3536
title = 'appName',
3637
titleText,
3738
}) => {
38-
const statisticsConsent = useGroupConsent('statistics');
39+
const statisticsConsent = useGroupConsent(COOKIE_CONSENT_GROUP.Statistics);
3940
const { t } = useTranslation();
4041
const location = useLocation();
4142
const { trackPageView } = useMatomo();

src/domain/app/routes/localeRoutes/LocaleRoutes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CookieSettingsPage } from 'hds-react';
12
import React from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { Navigate, Route, Routes, useParams } from 'react-router';
@@ -91,6 +92,7 @@ const LocaleRoutes: React.FC = () => {
9192
path={ROUTES.ACCESSIBILITY_STATEMENT}
9293
element={<AccessibilityStatementPage />}
9394
/>
95+
<Route path={ROUTES.COOKIES} element={<CookieSettingsPage />} />
9496
<Route path={ROUTES.CREATE_EVENT} element={<CreateEventPage />} />
9597
<Route path={ROUTES.EVENT_SAVED} element={<EventSavedPage />} />
9698
<Route path={ROUTES.EDIT_EVENT} element={<EditEventPage />} />

0 commit comments

Comments
 (0)