Skip to content

Commit

Permalink
Feat: Set shorter cookie expiration when only necessary category acce…
Browse files Browse the repository at this point in the history
…pted #CCM-53
  • Loading branch information
OndraM committed Jan 4, 2022
1 parent 10920c4 commit 929d8f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/LmcCookieConsentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const LmcCookieConsentManager: CookieConsentManager = (serviceName, args) => {
auto_language: autodetectLang ? 'document' : null, // Autodetect language based on `<html lang="...">` value
autorun: true, // Show the cookie consent banner as soon as possible
cookie_expiration: 365, // 1 year
cookie_necessary_only_expiration: 60, // 2 months
cookie_name: cookieName, // Predefined cookie name. Do not override.
current_lang: defaultLang, // Default language used when auto_language is false (or when autodetect failed)
delay: 0, // Show the modal immediately after init
Expand Down
6 changes: 5 additions & 1 deletion src/consentCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function submitConsent(
function buildPayload(cookieConsent: VanillaCookieConsent.CookieConsent<CookieConsentCategory>): Object {
const cookieData = cookieConsent.get('data');
const userPreferences = cookieConsent.getUserPreferences();
const daysOfAcceptation =
userPreferences.accept_type === VanillaCookieConsent.AcceptType.NECESSARY
? cookieConsent.getConfig('cookie_necessary_only_expiration')
: cookieConsent.getConfig('cookie_expiration');

return {
data: {
Expand All @@ -28,7 +32,7 @@ function buildPayload(cookieConsent: VanillaCookieConsent.CookieConsent<CookieCo
revision: cookieConsent.get('revision'),
source: cookieData.serviceName,
language: cookieConsent.getConfig('current_lang'),
days_of_acceptation: cookieConsent.getConfig('cookie_expiration'),
days_of_acceptation: daysOfAcceptation,
},
},
};
Expand Down

0 comments on commit 929d8f3

Please sign in to comment.