在以下模板中,我使用三个变量:GA_TRACKING_ID,CC_POPUP_BGCOL和CC_POPUP_TXTCOL
<script src="fileadmin/templates/js/cookieconsent.min.js" data-cfasync="false"></script>
<script>
function loadGAonConsent(){
var gs = document.createElement("script");
gs.async = true;
gs.src = "https://www.googletagmanager.com/gtag/js?id={GA_TRACKING_ID}";
var h = document.getElementsByTagName("head")[0];
h.appendChild(gs, h);
gs.onload = function (){
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', '{GA_TRACKING_ID}', { 'anonymize_ip': true });
testfunc('{CC_POPUP_BGCOL}', '{CC_POPUP_TXTCOL}');
}
}
if(document.cookie.split(';').filter(function(item){return item.indexOf('cookieconsent_status=allow') >= 0}).length)
loadGAonConsent();
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "{CC_POPUP_BGCOL}",
"text": "{CC_POPUP_TXTCOL}"
},
"button": {
"background": "#4b81e8"
}
},
"theme": "classic",
"type": "opt-in",
"content": {
"policy": "policy",
"message": "message",
"deny": "deny",
"allow": "allow",
"link": "link",
"href": "#"
},
onStatusChange:function(status,chosenBefore){
if(this.hasConsented())
loadGAonConsent();
}
});
</script>
GA_TRACKING_ID的所有外观均按预期设置,但JS-Funktion“ window.cookieconsent.initialise()”中并非全部CC_POPUP_xxx。
所以我在调用“ gtag()”之后添加了对不存在的func“ testfunc('{CC_POPUP_BGCOL}','{CC_POPUP_TXTCOL}')”的调用(以模拟一个简单的函数调用),并且令人惊讶的是这两个外观被替换。有人可以解释吗?