Async版のAdSense広告コードでページ読み込み時にコンテンツの幅が728px
以上の場合、デフォルトの300x250から728x90の広告に切り替えるコードの習作。
<ins class="adsbygoogle"
id="adsense-main"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
data-ad-slot="xxxxxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
(function (d) {
if (d.body.dataset) {
var p = d.getElementById('adsense-main');
var w = p.parentNode.clientWidth;
if (w >= 728) {
p.style.width = '728px';
p.style.height = '90px';
p.dataset.adSlot = 'xxxxxxxxxx';
}
}
}(document));
</script>