diff --git a/public/themes/custom/hdbt_subtheme/dist/js/matomo.min.js b/public/themes/custom/hdbt_subtheme/dist/js/matomo.min.js index 52425e03f..97c4ae16e 100644 --- a/public/themes/custom/hdbt_subtheme/dist/js/matomo.min.js +++ b/public/themes/custom/hdbt_subtheme/dist/js/matomo.min.js @@ -1 +1 @@ -!function(e,Drupal){function c(){if(void 0!==Drupal.eu_cookie_compliance&&Drupal.eu_cookie_compliance.hasAgreed("statistics")){const e=window._paq=window._paq||[];e.push(["trackPageView"]),e.push(["enableLinkTracking"]),function(){const c="//webanalytics.digiaiiris.com/js/";e.push(["setTrackerUrl",`${c}tracker.php`]),e.push(["setSiteId","1219"]);const i=document,n=i.createElement("script"),t=i.getElementsByTagName("script")[0];n.async=!0,n.src=`${c}piwik.min.js`,t.parentNode.insertBefore(n,t)}()}}e(document).on("eu_cookie_compliance.changeStatus",c()),e(document).ready(c)}(jQuery,Drupal); \ No newline at end of file +!function(e,Drupal){const t=()=>{if(Drupal.cookieConsent.getConsentStatus(["statistics"])){const e=window._paq=window._paq||[];e.push(["trackPageView"]),e.push(["enableLinkTracking"]),function(){const t="//webanalytics.digiaiiris.com/js/";e.push(["setTrackerUrl",`${t}tracker.php`]),e.push(["setSiteId","1219"]);const n=document,i=n.createElement("script"),s=n.getElementsByTagName("script")[0];i.async=!0,i.src=`${t}piwik.min.js`,s.parentNode.insertBefore(i,s)}()}};Drupal.cookieConsent.initialized()?t():Drupal.cookieConsent.loadFunction(t)}(jQuery,Drupal); \ No newline at end of file diff --git a/public/themes/custom/hdbt_subtheme/src/js/matomo.js b/public/themes/custom/hdbt_subtheme/src/js/matomo.js index 7a68ba381..6e730bc24 100644 --- a/public/themes/custom/hdbt_subtheme/src/js/matomo.js +++ b/public/themes/custom/hdbt_subtheme/src/js/matomo.js @@ -1,12 +1,9 @@ // eslint-disable-next-line func-names (function ($, Drupal) { - function loadMatomoAnalytics() { - if (typeof Drupal.eu_cookie_compliance === "undefined") { - return; - } + const loadMatomoAnalytics = () => { // Load Matomo only if statistics cookies are allowed. - if (Drupal.eu_cookie_compliance.hasAgreed("statistics")) { + if (Drupal.cookieConsent.getConsentStatus(['statistics'])) { // Matomo Tag Manager // eslint-disable-next-line no-multi-assign const _paq = (window._paq = window._paq || []); @@ -25,11 +22,12 @@ s.parentNode.insertBefore(g, s); })(); } - } + }; // Load when cookie settings are changed. - $(document).on("eu_cookie_compliance.changeStatus", loadMatomoAnalytics()); - - // Load on page load. - $(document).ready(loadMatomoAnalytics); + if (Drupal.cookieConsent.initialized()) { + loadMatomoAnalytics(); + } else { + Drupal.cookieConsent.loadFunction(loadMatomoAnalytics); + } })(jQuery, Drupal);