소스 검색

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`]);