From a00954f03972354f7879ab9be2c6ec6c940a0df4 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Mon, 25 Mar 2024 16:43:55 +0000 Subject: [PATCH 1/3] feat: add flag for if js snippet contains cookies This patch adds a flag to the js snippet creation page to allow the staff member to specify if the snippet contains analytical cookies. This will allow us to only apply the snippet if consent is given (if cookieConsent is enabled) --- code/web/sys/DBMaintenance/version_updates/24.05.00.php | 9 +++++++++ code/web/sys/LocalEnrichment/JavaScriptSnippet.php | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/code/web/sys/DBMaintenance/version_updates/24.05.00.php b/code/web/sys/DBMaintenance/version_updates/24.05.00.php index 245052c871..fbf309d780 100644 --- a/code/web/sys/DBMaintenance/version_updates/24.05.00.php +++ b/code/web/sys/DBMaintenance/version_updates/24.05.00.php @@ -82,6 +82,15 @@ function getUpdates24_05_00(): array { ] ] //other + //jacob - PTFS Europe + 'Snippet_Contains_Analytics_Cookies' => [ + 'title' => 'JS Snippet Contains Analytics Cookies', + 'description' => 'Add a toggle for if a JS snippet contains analytics cookies or not.', + 'continueOnError' => true, + 'sql' => [ + 'ALTER TABLE javascript_snippets ADD COLUMN containsAnalyticsCookies TINYINT(1)' + ] + ], //Snippet_Contains_Marketing_Cookies ]; diff --git a/code/web/sys/LocalEnrichment/JavaScriptSnippet.php b/code/web/sys/LocalEnrichment/JavaScriptSnippet.php index d362e4225f..ace666138c 100644 --- a/code/web/sys/LocalEnrichment/JavaScriptSnippet.php +++ b/code/web/sys/LocalEnrichment/JavaScriptSnippet.php @@ -9,6 +9,7 @@ class JavaScriptSnippet extends DB_LibraryLocationLinkedObject { public $id; public $name; public $snippet; + public $containsAnalyticsCookies; protected $_libraries; protected $_locations; @@ -57,6 +58,13 @@ public static function getObjectStructure($context = ''): array { 'values' => $locationList, 'hideInLists' => true, ], + + 'containsAnalyticsCookies' => [ + 'property' => 'containsAnalyticsCookies', + 'type' => 'checkbox', + 'label' => 'Contains Analytics Cookies', + 'description' => 'This snippet contains analytics cookies', + ], ]; } From f54154cf96a9b9c15d5b9286464efcadefd66e2e Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Tue, 23 Apr 2024 10:12:35 +0100 Subject: [PATCH 2/3] feat: only load jssnippet if allowed by cookie prefs This patch checks to see if cookie consent is enabled and only loads the jssnippet if consent is given (must check flag that snippet contains cookies for this to apply) --- code/web/sys/Interface.php | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/code/web/sys/Interface.php b/code/web/sys/Interface.php index 8eb565255b..2d27d59870 100644 --- a/code/web/sys/Interface.php +++ b/code/web/sys/Interface.php @@ -535,6 +535,18 @@ function loadDisplayOptions($fromBookCoverProcessing = false) { $customJavascript = ''; if (!isset($_REQUEST['noCustomJavaScript']) && !isset($_REQUEST['noCustom'])) { try { + if (isset($_COOKIE["cookieConsent"])) { + $cookie = json_decode(urldecode($_COOKIE["cookieConsent"]), true); + if ($cookie != null) { + $analyticsPref = $cookie['Analytics']; + }else{ + $analyticsPref = 0; + } + }else{ + $cookie = null; + $analyticsPref = 0; + } + if (isset($location)) { require_once ROOT_DIR . '/sys/LocalEnrichment/JavaScriptSnippetLocation.php'; $javascriptSnippetLocation = new JavaScriptSnippetLocation(); @@ -545,10 +557,15 @@ function loadDisplayOptions($fromBookCoverProcessing = false) { $javascriptSnippet = new JavaScriptSnippet(); $javascriptSnippet->id = $javascriptSnippetLocation->javascriptSnippetId; if ($javascriptSnippet->find(true)) { - if (strlen($customJavascript) > 0) { - $customJavascript .= "\n"; + if (empty($library->cookieStorageConsent) || + (!empty($library->cookieStorageConsent) && empty($javascriptSnippet->containsAnalyticsCookies)) || + (!empty($library->cookieStorageConsent) && !empty($javascriptSnippet->containsAnalyticsCookies) && $analyticsPref == 1) + ) { + if (strlen($customJavascript) > 0) { + $customJavascript .= "\n"; + } + $customJavascript .= trim($javascriptSnippet->snippet); } - $customJavascript .= trim($javascriptSnippet->snippet); } } } else { @@ -561,10 +578,15 @@ function loadDisplayOptions($fromBookCoverProcessing = false) { $javascriptSnippet = new JavaScriptSnippet(); $javascriptSnippet->id = $javascriptSnippetLibrary->javascriptSnippetId; if ($javascriptSnippet->find(true)) { - if (strlen($customJavascript) > 0) { - $customJavascript .= "\n"; + if (empty($library->cookieStorageConsent) || + (!empty($library->cookieStorageConsent) && empty($javascriptSnippet->containsAnalyticsCookies)) || + (!empty($library->cookieStorageConsent) && !empty($javascriptSnippet->containsAnalyticsCookies) && $analyticsPref == 1) + ) { + if (strlen($customJavascript) > 0) { + $customJavascript .= "\n"; + } + $customJavascript .= trim($javascriptSnippet->snippet); } - $customJavascript .= trim($javascriptSnippet->snippet); } } } From bedeec0e2f4e3b48e88c325151f1097c79bcd1d0 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Tue, 23 Apr 2024 10:37:53 +0100 Subject: [PATCH 3/3] chore: update release_notes --- code/web/release_notes/24.05.00.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/web/release_notes/24.05.00.MD b/code/web/release_notes/24.05.00.MD index cc5361a6ae..c9cd74e596 100644 --- a/code/web/release_notes/24.05.00.MD +++ b/code/web/release_notes/24.05.00.MD @@ -120,7 +120,7 @@ //Jacob ### Data Protection Updates - Fixed issue where Cookie Consent banner would not disappear while not logged in, regardless of cookie preferences. (JOM) - +- Added the ability to only apply JS-Snippets if cookie consent is given while "Require Cookie Consent" is enabled. (JOM) ## This release includes code contributions from - ByWater Solutions