2 回答
TA贡献2011条经验 获得超2个赞
下面是一个片段,您可以使用它向网页添加异步脚本。将其包裹在您的病情中,您就可以开始了。
const gScript = document.createElement('script');
gScript.src = "https://www.googletagmanager.com/gtag/js?id=AW-mycode";
gScript.type = 'text/javascript';
gScript.onload = () => {
console.log('Script has been fully loaded');
// initlaize anything you want that needs to be done after script has loaded
// Below code in your case
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-mycode');
};
gScript.async = true;
gScript.charset = 'utf-8';
document.getElementsByTagName('head')[0].appendChild(gScript);
希望这可以帮助 :)
TA贡献1810条经验 获得超4个赞
尝试这个:
<script>
if(cookieNo!="1"){
var googleAds = document.createElement('script');
googleAds.src = "https://www.googletagmanager.com/gtag/js?id=AW-mycode";
document.head.appendChild(googleAds);
//Other code
}
</script>
添加回答
举报