为了遵守德国的GDPR法律,我正在尝试通过简单的本地安装Matomo(以前称为Piwik)分析和Insite的Cookieconsent来实施用户同意选项(选择Cookie和跟踪)没有CMS的静态网站。
我已经阅读了以下相关指南,但缺乏实现自己的解决方案的JavaScript技能:
https://developer.matomo.org/guides/tracking-javascript-guide#asking-for-consent
https://developer.matomo.org/api-reference/tracking-javascript
https://cookieconsent.insites.com/documentation/disabling-cookies/
我发现的最完整的指南是(德语): https://wwagner.net/typo3/opt-in-loesung-typo3-matomo/
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['requireConsent']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);</script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.6/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#edeff5",
"text": "#838391"
},
"button": {
"background": "#4b81e8"
}
},
"theme": "edgeless",
"type": "opt-in",
"content": {
"message": "Diese Webseite verwendet Cookies und Matomo/Piwik, um die Bedienfreundlichkeit zu erhöhen.",
"dismiss": "Ablehnen",
"allow": "OK",
"link": "Weitere Informationen",
"href": "/datenschutz"
},
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
console.log('onInitialise in - begin' );
console.log(type );
console.log(didConsent);
console.log('onInitialise in - end' );
_paq.push(['rememberConsentGiven']);
// Dieser Teil kommt aus dem Matomo/Piwik Code
(function() {
var u="//mysite.de/piwik/";
_paq.push(['setTrackerUrl', u+'js/']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'js/'; s.parentNode.insertBefore(g,s);
})();
}
if (type == 'opt-in' && !didConsent) {
// disable cookies
console.log('onInitialise out - begin' );
console.log(type );
console.log(didConsent);
console.log('onInitialise out - end' );
_paq.push(['forgetConsentGiven']);
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
console.log('onStatusChange in - begin' );
console.log(type );
console.log(didConsent);
console.log('onStatusChange in - end' );
_paq.push(['rememberConsentGiven']);
// Dieser Teil kommt aus dem Matomo/Piwik Code
(function() {
var u="//mysite/piwik/";
_paq.push(['setTrackerUrl', u+'js/']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'js/'; s.parentNode.insertBefore(g,s);
})();
}
if (type == 'opt-in' && !didConsent) {
// disable cookies
console.log('onStatusChange out - begin' );
console.log(type );
console.log(didConsent);
console.log('onStatusChange out - end' );
_paq.push(['forgetConsentGiven']);
}
}
})
});</script>
据报道,博客用户可以使用。在我的测试中,无论用户选择如何(但仅在做出选择时),都会设置cookie并跟踪用户操作。 在接受或拒绝以下4种cookie时,将设置它们:cookieconsent_status(内容:关闭或允许),_ pk_id,_pk_ses,mtm_consent。 我正在尝试查明错误的根源,任何解决方案(可能完全没有Cookie同意)将不胜感激。