Skip to content

Commit

Permalink
Merge pull request #600 from City-of-Helsinki/UHF-8678
Browse files Browse the repository at this point in the history
UHF-8678 Use Drupal.cookieConsent functions
  • Loading branch information
khalima authored Dec 4, 2024
2 parents cf4a18d + 536e64a commit bd7b8c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ siteimprove-analytics:
dist/js/siteimprove_analytics.min.js: {}
dependencies:
- core/drupal
- eu_cookie_compliance/eu_cookie_compliance

# Turn datetime into text, f.ex "today"
datetime_comparison:
Expand Down
20 changes: 9 additions & 11 deletions public/themes/custom/hdbt_subtheme/src/js/siteimprove_analytics.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// eslint-disable-next-line func-names
(function (Drupal) {
function loadSiteimproveAnalytics() {
if (typeof Drupal.eu_cookie_compliance === 'undefined') {
return;
}
const loadSiteimproveAnalytics = () => {

// Load Siteimprove analytics only if statistics cookies are allowed.
if (Drupal.eu_cookie_compliance.hasAgreed('statistics')) {
if (Drupal.cookieConsent.getConsentStatus(['statistics'])) {
// eslint-disable-next-line no-multi-assign
const d = document;
const b = d.body;
Expand All @@ -16,11 +13,12 @@
g.src = '//siteimproveanalytics.com/js/siteanalyze_6047173.js';
b.appendChild(g);
}
}
};

// Load when cookie settings are changed.
document.addEventListener('eu_cookie_compliance.changeStatus', loadSiteimproveAnalytics, false);

// Load on page load.
document.addEventListener('DOMContentLoaded', loadSiteimproveAnalytics, false);
// Initialize Siteimprove analytics.
if (Drupal.cookieConsent.initialized()) {
loadSiteimproveAnalytics();
} else {
Drupal.cookieConsent.loadFunction(loadSiteimproveAnalytics);
}
})(Drupal);

0 comments on commit bd7b8c3

Please sign in to comment.