谷歌AD代码

低调G
2021-04-17 / 0 评论 / 634 阅读 / 正在检测是否收录...
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 自适应纵向AD -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9880195064782685"
     data-ad-slot="6204667653"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 自适应正方形AD -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9880195064782685"
     data-ad-slot="5278598793"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 自适应横向AD -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9880195064782685"
     data-ad-slot="5055237513"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

优化谷歌广告代码,使其后加载,不影响博客加载速度。
将:<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
替换为:

<script>
window.onload = function() {
        setTimeout(function() {
                let script = document.createElement("script");
                script.setAttribute("async", "");
                script.src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
                document.body.appendChild(script);
        }, 2e3);
}
</script>

自动广告代码:<script data-ad-client="ca-pub-9880195064782685" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

优化代码:

<script>
window.onload = function() {
        setTimeout(function() {
                let script = document.createElement("script");
                script.setAttribute("data-ad-client", "ca-pub-你的id");
                script.setAttribute("async", "");
                script.src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?";
                document.body.appendChild(script);
        }, 0);
};
</script>
0

评论 (0)

取消