From 7672661e3f24b2fa293ad067e2e2fdd970e6dc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Glawaty?= Date: Fri, 10 May 2024 04:34:30 +0200 Subject: [PATCH] Updated the package version and CHANGELOG --- CHANGELOG.md | 7 +++++++ gtm_template.tpl | 17 +++++++++++++---- package-lock.json | 4 ++-- package.json | 2 +- src/Config/PluginOptions.js | 4 ++-- src/CookieConsentWrapper.js | 11 +++++++++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b09757..ea95925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.5.3] - 2024-05-10 + +### Added + +- Added field `User RFC cookie` into the GTM template. +- Added property `CookieConsentWrapper.consentCookieValue` that returns raw consent value as a string or null if no consent exists. + ## [0.5.2] - 2024-04-04 ### Fixed diff --git a/gtm_template.tpl b/gtm_template.tpl index 10a4b68..a679681 100644 --- a/gtm_template.tpl +++ b/gtm_template.tpl @@ -467,6 +467,14 @@ ___TEMPLATE_PARAMETERS___ ], "help": "One name per line.", "lineCount": 3 + }, + { + "type": "CHECKBOX", + "name": "use_rfc_cookie", + "checkboxText": "Use RFC cookie", + "simpleValueType": true, + "defaultValue": false, + "help": "The cookie value will be encoded using the \u003ccode\u003eencodeURIComponent\u003c/code\u003e function (so the cookie value will be RFC compliant) if the option is enabled. Otherwise, the cookie will contain plain JSON." } ] }, @@ -2073,12 +2081,12 @@ const temporaryWrapper = (function () { setInWindow('CookieConsentWrapper', temporaryWrapper, false); -// parse consents from cookies -let consentCookie = getCookieValues(data.cookie_name)[0] || null; +// parse consents from cookies, values are automatically decoded using decodeURIComponent function if the second argument is true +let consentCookie = getCookieValues(data.cookie_name, true)[0] || null; if (null !== consentCookie) { consentCookie = JSON.parse(consentCookie); - consentCookie = consentCookie.hasOwnProperty('level') && consentCookie.level.length ? consentCookie.level : []; + consentCookie = consentCookie && consentCookie.hasOwnProperty('categories') && consentCookie.categories.length ? consentCookie.categories : []; } // build storage pool & event triggers @@ -2274,7 +2282,8 @@ const pluginOptions = { revision: makeInteger(data.revision), delay: makeInteger(data.delay), auto_language: 'disabled' !== data.locale_detection_strategy ? data.locale_detection_strategy : null, - page_scripts: data.page_scripts + page_scripts: data.page_scripts, + use_rfc_cookie: data.use_rfc_cookie }; if (data.hasOwnProperty('current_locale')) { diff --git a/package-lock.json b/package-lock.json index dc5eced..3a57580 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "68publishers-cookie-consent", - "version": "0.5.2", + "version": "0.5.3-beta.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "68publishers-cookie-consent", - "version": "0.5.2", + "version": "0.5.3-beta.0", "license": "MIT", "dependencies": { "crypto-js": "^4.1.1", diff --git a/package.json b/package.json index 647c682..dfe6d9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "68publishers-cookie-consent", - "version": "0.5.2", + "version": "0.5.3-beta.0", "description": "Cookie consent wrapper based on orestbida/cookieconsent with GTM integration.", "homepage": "http://www.68publishers.io/", "main": "index.js", diff --git a/src/Config/PluginOptions.js b/src/Config/PluginOptions.js index 17e4f28..a79516c 100644 --- a/src/Config/PluginOptions.js +++ b/src/Config/PluginOptions.js @@ -16,12 +16,12 @@ class PluginOptions extends require('./AbstractOptions') { this.auto_language = 'document'; this.page_scripts = false; this.script_selector = 'data-cookiecategory'; + this.cookie_domain = window.location.hostname; + this.use_rfc_cookie = false; // another options for the original plugin this.cookie_path = '/'; - this.cookie_domain = window.location.hostname; this.cookie_same_site = 'Lax'; - this.use_rfc_cookie = false; this.remove_cookie_tables = false; // unsupported options (custom reimplementation) diff --git a/src/CookieConsentWrapper.js b/src/CookieConsentWrapper.js index 3492921..0aaf8dd 100644 --- a/src/CookieConsentWrapper.js +++ b/src/CookieConsentWrapper.js @@ -69,6 +69,17 @@ class CookieConsentWrapper { return this._cookieTables; } + get consentCookieValue() { + if (!this._cookieConsent.validConsent()) { + return null; + } + + const cookieName = this._config.pluginOptions.cookie_name; + let cookieValue = document.cookie.match("(^|;)\\s*" + cookieName + "\\s*=\\s*([^;]+)"); + + return cookieValue ? cookieValue.pop() : null; + } + get consentCookieData() { const cookieName = this._config.pluginOptions.cookie_name; let cookieValue = document.cookie.match("(^|;)\\s*" + cookieName + "\\s*=\\s*([^;]+)");