From 519182d437296e51db085eef7aac8ffc1ccf996e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Wed, 17 Nov 2021 22:51:21 +0100 Subject: [PATCH] Feat: Generate and store consent UUID on accept #CCM-35 --- package.json | 1 + src/LmcCookieConsentManager.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/package.json b/package.json index 8f8cef5d..4f2fb18a 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ }, "dependencies": { "@lmc-eu/spirit-design-tokens": "^0.4.0", + "nanoid": "^3.1.30", "vanilla-cookieconsent": "^2.6.1" }, "devDependencies": { diff --git a/src/LmcCookieConsentManager.js b/src/LmcCookieConsentManager.js index c6943cef..d136602d 100644 --- a/src/LmcCookieConsentManager.js +++ b/src/LmcCookieConsentManager.js @@ -1,4 +1,5 @@ import 'vanilla-cookieconsent'; +import { nanoid } from 'nanoid'; import { config as configCs } from './languages/cs'; import { config as configDe } from './languages/de'; @@ -91,6 +92,14 @@ const LmcCookieConsentManager = (serviceName, args) => { onAccept(cookie, cookieConsent); if (isFirstTimeAccept) { + const cookieData = cookieConsent.get('data'); + if (cookieData === null || !('uid' in cookieData)) { + cookieConsent.set('data', { + value: { serviceName: serviceName, uid: nanoid() }, + mode: 'update', + }); + } + onFirstAccept(cookie, cookieConsent); acceptedOnlyNecessary ? onFirstAcceptOnlyNecessary(cookie, cookieConsent)