diff --git a/mon-entreprise/source/ATInternetTracking/Tracker.ts b/mon-entreprise/source/ATInternetTracking/Tracker.ts index 0019dad02..b9f42369d 100644 --- a/mon-entreprise/source/ATInternetTracking/Tracker.ts +++ b/mon-entreprise/source/ATInternetTracking/Tracker.ts @@ -43,6 +43,7 @@ export interface ATTracker { privacy: { setVisitorMode(authority: 'cnil', type: 'exempt'): void setVisitorOptout(): void + getVisitorMode(): { name: 'exempt' | 'optout' } } dispatch(): void } @@ -55,7 +56,7 @@ declare global { } } -export function createTracker(siteId?: string) { +export function createTracker(siteId?: string, doNotTrack = false) { const site = siteId ? +siteId : 0 if (Number.isNaN(site)) { throw new Error('expect string siteId to be of number form') @@ -75,18 +76,11 @@ export function createTracker(siteId?: string) { this.site[ INDICATOR.SITE.LANGAGE ] = `[${options.language}]` as CustomSiteIndicator[1] - this.privacy.setVisitorMode('cnil', 'exempt') - if ( - process.env.NODE_ENV === 'production' && - (document.cookie - .split(';') - // We use Matomo cookie while it's here - .find((cookie) => cookie.startsWith('mtm_consent_removed')) || - navigator.doNotTrack === '1') - ) { + if (process.env.NODE_ENV === 'production' && doNotTrack) { this.privacy.setVisitorOptout() + } else { + this.privacy.setVisitorMode('cnil', 'exempt') } - this.dispatch() } dispatch() { @@ -123,6 +117,10 @@ export class Log implements ATTracker { setVisitorOptout() { console.debug('ATTracker::setVisitorOptout') }, + getVisitorMode() { + console.debug('ATTracker::privacy.getVisitorMode') + return { name: 'exempt' } + }, } dispatch(): void { console.debug('ATTracker::dispatch') diff --git a/mon-entreprise/source/Provider.tsx b/mon-entreprise/source/Provider.tsx index 54573bf7a..ce33d4472 100644 --- a/mon-entreprise/source/Provider.tsx +++ b/mon-entreprise/source/Provider.tsx @@ -18,9 +18,17 @@ import { // ATInternet Tracking import { TrackingContext } from './ATInternetTracking' import { createTracker } from './ATInternetTracking/Tracker' +import safeLocalStorage from './storage/safeLocalStorage' import { inIframe } from './utils' -const ATTracker = createTracker(process.env.AT_INTERNET_SITE_ID) +const ATTracker = createTracker( + process.env.AT_INTERNET_SITE_ID, + !!JSON.parse( + safeLocalStorage.getItem('tracking:do_not_track') ?? + navigator.doNotTrack ?? + 'false' + ) +) declare global { interface Window { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: any diff --git a/mon-entreprise/source/components/layout/Footer/Privacy.tsx b/mon-entreprise/source/components/layout/Footer/Privacy.tsx index 7b9eadd1b..0becb215c 100644 --- a/mon-entreprise/source/components/layout/Footer/Privacy.tsx +++ b/mon-entreprise/source/components/layout/Footer/Privacy.tsx @@ -1,7 +1,8 @@ import Overlay from 'Components/Overlay' -import { useState } from 'react' -import { Trans, useTranslation } from 'react-i18next' -import { TrackPage } from '../../../ATInternetTracking' +import { useCallback, useContext, useState } from 'react' +import { Trans } from 'react-i18next' +import { TrackingContext, TrackPage } from '../../../ATInternetTracking' +import safeLocalStorage from '../../../storage/safeLocalStorage' export default function Privacy({ label }: { label?: string }) { const [opened, setOpened] = useState(false) @@ -28,7 +29,22 @@ export default function Privacy({ label }: { label?: string }) { } function PrivacyContent() { - const { language } = useTranslation().i18n + const tracker = useContext(TrackingContext) + const [valueChanged, setValueChanged] = useState(false) + const handleChange = useCallback( + (evt) => { + if (evt.target.checked) { + tracker.privacy.setVisitorOptout() + safeLocalStorage.setItem('tracking:do_not_track', 'true') + } else { + tracker.privacy.setVisitorMode('cnil', 'exempt') + safeLocalStorage.setItem('tracking:do_not_track', 'false') + } + setValueChanged(true) + }, + [setValueChanged, tracker.privacy] + ) + return ( <> @@ -46,17 +62,30 @@ function PrivacyContent() {

Vous pouvez vous soustraire de cette mesure d'utilisation du site - ci-dessous. + ci-dessous : +

+

+

-