-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
declare module 'vanilla-cookieconsent' { | ||
interface CookieValue { | ||
categories: { | ||
necessary: boolean; | ||
analytics: boolean; | ||
}; | ||
} | ||
|
||
interface CookieConsentCallbackParam { | ||
cookie: CookieValue; | ||
} | ||
|
||
interface CookieConsentConfig { | ||
categories: { | ||
necessary: { | ||
enabled: boolean; | ||
readOnly: boolean; | ||
}; | ||
analytics: { | ||
enabled: boolean; | ||
}; | ||
}; | ||
language: { | ||
default: string; | ||
translations: { | ||
[key: string]: { | ||
consentModal: { | ||
title: string; | ||
description: string; | ||
acceptAllBtn: string; | ||
acceptNecessaryBtn: string; | ||
showPreferencesBtn: string; | ||
}; | ||
preferencesModal: { | ||
title: string; | ||
acceptAllBtn: string; | ||
acceptNecessaryBtn: string; | ||
savePreferencesBtn: string; | ||
closeIconLabel: string; | ||
sections: Array<{ | ||
title: string; | ||
description: string; | ||
linkedCategory?: string; | ||
}>; | ||
}; | ||
}; | ||
}; | ||
}; | ||
onFirstConsent?: (param: CookieConsentCallbackParam) => void; | ||
onConsentChange?: (param: CookieConsentCallbackParam) => void; | ||
} | ||
|
||
export function run(config: CookieConsentConfig): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import 'vanilla-cookieconsent/dist/cookieconsent.css'; | ||
import * as CookieConsent from 'vanilla-cookieconsent'; | ||
import LeadinfoScript from '../components/layout/leadinfo-script'; | ||
|
||
const CookieConsentComponentV3 = () => { | ||
const [analyticsEnabled, setAnalyticsEnabled] = useState(false); | ||
|
||
useEffect(() => { | ||
CookieConsent.run({ | ||
categories: { | ||
necessary: { | ||
enabled: true, | ||
readOnly: true, | ||
}, | ||
analytics: { | ||
enabled: false, | ||
}, | ||
}, | ||
language: { | ||
default: 'en', | ||
translations: { | ||
en: { | ||
consentModal: { | ||
title: 'We use cookies', | ||
description: | ||
'This website uses cookies to ensure the best user experience.', | ||
acceptAllBtn: 'Accept all', | ||
acceptNecessaryBtn: 'Reject all', | ||
showPreferencesBtn: 'Manage preferences', | ||
}, | ||
preferencesModal: { | ||
title: 'Manage Cookie Preferences', | ||
acceptAllBtn: 'Accept all', | ||
acceptNecessaryBtn: 'Accept necessary only', | ||
savePreferencesBtn: 'Save preferences', | ||
closeIconLabel: 'Close', | ||
sections: [ | ||
{ | ||
title: 'Strictly Necessary Cookies', | ||
description: | ||
'These cookies are essential for website functionality and cannot be disabled.', | ||
linkedCategory: 'necessary', | ||
}, | ||
{ | ||
title: 'Analytics Cookies', | ||
description: | ||
'We use analytics cookies to analyze website usage and improve our services.', | ||
linkedCategory: 'analytics', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
onFirstConsent: (param) => { | ||
handleConsent(param.cookie.categories); | ||
}, | ||
onConsentChange: (param) => { | ||
handleConsent(param.cookie.categories); | ||
}, | ||
}); | ||
}, []); | ||
|
||
const handleConsent = (categories) => { | ||
const isAnalyticsAccepted = categories.includes('analytics'); | ||
|
||
if (isAnalyticsAccepted) { | ||
setAnalyticsEnabled(true); | ||
setLeadinfoCookies(); | ||
} else { | ||
setAnalyticsEnabled(false); | ||
clearLeadinfoCookies(); | ||
} | ||
}; | ||
|
||
const setLeadinfoCookies = () => { | ||
const twoYears = 63072000; | ||
const sessionValue = new Date().toISOString(); | ||
document.cookie = `_li_id=some_value; max-age=${twoYears}; path=/`; | ||
document.cookie = `_li_ses=${sessionValue}; max-age=0; path=/`; | ||
}; | ||
|
||
const clearLeadinfoCookies = () => { | ||
document.cookie = '_li_id=; max-age=0; path=/'; | ||
document.cookie = '_li_ses=; max-age=0; path=/'; | ||
}; | ||
|
||
return <LeadinfoScript enable={analyticsEnabled} />; | ||
}; | ||
|
||
export default CookieConsentComponentV3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15148,6 +15148,11 @@ value-or-promise@^1.0.12: | |
resolved "https://registry.yarnpkg.com/value-or-promise/-/value-or-promise-1.0.12.tgz#0e5abfeec70148c78460a849f6b003ea7986f15c" | ||
integrity sha512-Z6Uz+TYwEqE7ZN50gwn+1LCVo9ZVrpxRPOhOLnncYkY1ZzOYtrX8Fwf/rFktZ8R5mJms6EZf5TqNOMeZmnPq9Q== | ||
|
||
[email protected]: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/vanilla-cookieconsent/-/vanilla-cookieconsent-3.0.1.tgz#059d1b2c712476ae4172d4ec7fa9d553a16be12d" | ||
integrity sha512-gqc4x7O9t1I4xWr7x6/jtQWPr4PZK26SmeA0iyTv1WyoECfAGnu5JEOExmMEP+5Fz66AT9OiCBO3GII4wDQHLw== | ||
|
||
vary@^1, vary@~1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" | ||
|