codefog / contao-cookiebar

Display the information about cookies on your Contao website
MIT License
26 stars 9 forks source link

Opt-in variant -> no data in Google Analytics #67

Closed federleicht closed 4 years ago

federleicht commented 4 years ago

Hello codefog,

I would like to implement the "Opt-In" variant and have accordingly inserted the following line in the "analytics_google.html5" template:

window['ga-disable-<?= $GoogleAnalyticsId ?>'] = !localStorage.getItem('COOKIEBAR_ANALYTICS');

However, no data has been recorded in the last few days. What can be the problem here? Implemented on www.federleicht.cc

Thanks, Markus

qzminski commented 4 years ago

Your implementation looks correct, although there is some extra code that might prevent GA from working:

<script>var gaProperty='UA-30338188-13';var disableStr='ga-disable-'+gaProperty;if(document.cookie.indexOf(disableStr+'=true')>-1){window[disableStr]=!0}
function gaOptout(){document.cookie=disableStr+'=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';window[disableStr]=!0}</script>
federleicht commented 4 years ago

thank you, that's it! The script was responsible for setting an opt-out cookie: https://erdmann-freunde.de/logbuch/analytics-contao-datenschutz/

Is there perhaps other solution to get an opt-out-link?

qzminski commented 4 years ago

The extension does not provide that out of the box but you should be able to achieve that using some simple JS. All you have to do is to adjust the localStorage item COOKIEBAR_ANALYTICS.