ソースを参照

Enable Matomo's cookieless analytics.

Andrea Franceschini 2 年 前
コミット
f9c797da3f
2 ファイル変更9 行追加1 行削除
  1. 7 0
      components/CookieMonster.vue
  2. 2 1
      plugins/matomo.client.ts

+ 7 - 0
components/CookieMonster.vue

@@ -40,6 +40,7 @@ const error = useError();
 const isOpen = useState('isOpen', () => !consentStore.preferenceGiven && error.value === undefined);
 
 const rejectAll = () => {
+    window._paq.push(['forgetCookieConsentGiven']);
     consentStore.analytics = false;
     consentStore.ads = false;
     consentStore.preferenceGiven = true;
@@ -47,6 +48,7 @@ const rejectAll = () => {
 }
 
 const acceptAll = () => {
+    window._paq.push(['rememberCookieConsentGiven']);
     consentStore.analytics = true;
     consentStore.ads = true;
     consentStore.preferenceGiven = true;
@@ -56,6 +58,11 @@ const acceptAll = () => {
 const acceptMyChoice = () => {
     consentStore.preferenceGiven = true;
     isOpen.value = false;
+    if (consentStore.analytics) {
+        window._paq.push(['rememberCookieConsentGiven']);
+    } else {
+        window._paq.push(['forgetCookieConsentGiven']);
+    }
 }
 </script>
 

+ 2 - 1
plugins/matomo.client.ts

@@ -6,9 +6,10 @@ export default defineNuxtPlugin(_nuxtApp => {
     const consentStore = useCookie('consent-store').value as ConsentStore;
     const analytics = consentStore?.analytics;
 
-    if (analytics) {
+    if (analytics || true) {
         const u = "https://matomo.morpheu5.net/";
         const _paq = window._paq = window._paq || [];
+        _paq.push(['requireCookieConsent']);
         _paq.push(['trackPageView']);
         _paq.push(['enableLinkTracking']);
         _paq.push(['setTrackerUrl', `${u}matomo.php`]);