|
1 | | -import { CookieConsentReactProps } from 'hds-react'; |
| 1 | +import { CookieConsentChangeEvent, CookieConsentReactProps } from 'hds-react'; |
2 | 2 |
|
3 | 3 | import { PAGE_HEADER_ID } from '../../../constants'; |
4 | 4 | import useLocale from '../../../hooks/useLocale'; |
5 | 5 | import siteSettings from './data/siteSettings.json'; |
6 | 6 |
|
| 7 | +export enum COOKIE_CONSENT_GROUP { |
| 8 | + Tunnistamo = 'tunnistamo', |
| 9 | + UserInputs = 'userInputs', |
| 10 | + Shared = 'shared', |
| 11 | + Statistics = 'statistics', |
| 12 | +} |
| 13 | + |
7 | 14 | const useCookieConsentSettings = () => { |
8 | 15 | const locale = useLocale(); |
9 | 16 |
|
10 | 17 | 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 | + }, |
13 | 33 | siteSettings: siteSettings, |
14 | 34 | options: { focusTargetSelector: `#${PAGE_HEADER_ID}`, language: locale }, |
15 | 35 | }; |
|
0 commit comments