gpt4 book ai didi

javascript - 在 Javascript 函数中插入 Google 再营销代码

转载 作者:行者123 更新时间:2023-12-03 16:47:16 25 4
gpt4 key购买 nike

我正在尝试将 Google 再营销代码插入到 CookieCuttr 的 Javascript 函数中,以阻止 cookie。

我使用CookieCuttr代码来屏蔽cookie,功能如下:

<script>
function cookiestart(){
[ ... ]
}

if (jQuery.cookie('cc_cookie_accept') == 'cc_cookie_accept') {

HERE GOES THE GOOGLE ANALYTICS CODE

}
</script>

这非常有效:Google Analytics cookie 会被阻止,直到访问者接受它们。现在,我必须包括在...

<script>
[...]
</script>

...Google 再营销代码部分:

<!-- Google Code per il tag di remarketing -->
<!--------------------------------------------------
I tag di remarketing possono non essere associati a informazioni di identificazione personale o inseriti in pagine relative a categorie sensibili. Ulteriori informazioni e istruzioni su come impostare il tag sono disponibili alla pagina: http://google.com/ads/remarketingsetup
--------------------------------------------------->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/123456789/?value=0&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

有没有办法在之前的代码中包含这段代码?

谢谢大家

最佳答案

这应该可以满足您的需求。您的代码何时被调用并不明显,因此这会等到文档加载完毕后才添加分析代码。这是基于 Can I add javascript dynamically to an existing script element 中的答案

document.addEventListener("DOMContentLoaded", function() {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.appendChild(document.createTextNode("\
/* <![CDATA[ */\n\
var google_conversion_id = 123456789;\n\
var google_custom_params = window.google_tag_params;\n\
var google_remarketing_only = true;\n\
/* ]]> */\n\
"));
document.body.appendChild(script);
script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", "//www.googleadservices.com/pagead/conversion.js");
document.body.appendChild(script);
var noscript = document.createElement("noscript");
noscript.innerHTML =
'<div style="display:inline;">\
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/123456789/?value=0&amp;guid=ON&amp;script=0"/>\n\
</div>';
document.body.appendChild(noscript);
}, false);

关于javascript - 在 Javascript 函数中插入 Google 再营销代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com