diff --git a/code/web/release_notes/24.05.00.MD b/code/web/release_notes/24.05.00.MD index 982d578d67..5f3c66b2f6 100644 --- a/code/web/release_notes/24.05.00.MD +++ b/code/web/release_notes/24.05.00.MD @@ -126,7 +126,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 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); } } } diff --git a/code/web/sys/LocalEnrichment/JavaScriptSnippet.php b/code/web/sys/LocalEnrichment/JavaScriptSnippet.php index 024caf154d..7d2a0ded6b 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; @@ -63,6 +64,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', + ], ]; }