Skip to content

Commit

Permalink
Merge branch 'PTFS-Europe-cookieConsentSnippets' into 24.05.00
Browse files Browse the repository at this point in the history
  • Loading branch information
mdnoble73 committed Apr 30, 2024
2 parents 77dd248 + 448c1de commit 6241689
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion code/web/release_notes/24.05.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 28 additions & 6 deletions code/web/sys/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions code/web/sys/LocalEnrichment/JavaScriptSnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class JavaScriptSnippet extends DB_LibraryLocationLinkedObject {
public $id;
public $name;
public $snippet;
public $containsAnalyticsCookies;

protected $_libraries;
protected $_locations;
Expand Down Expand Up @@ -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',
],
];
}

Expand Down

0 comments on commit 6241689

Please sign in to comment.