I am using google adsense responsive ads. Sometimes adsense don't find ant ad and leave blank space. Is there a way, using a javascript to determine if an adsense block is empty? and than i will hide the entire adsense container.
Here is the code i've been using for the adsense:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sidebar skyscrapper -->
<ins class="adsbygoogle"
style="display: block; width: 300px; height: 600px"
data-ad-client="ca-pub-xxxxxx"
data-ad-slot="xxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sidebar skyscrapper -->
<ins class="adsbygoogle"
style="display: block; width: 300px; height: 600px"
data-ad-client="ca-pub-xxxxxx"
data-ad-slot="xxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Create a display ad unit in your AdSense account, making sure you leave Responsive selected in the "Ad size" section. Note down the following information from your responsive ad code: Your ad unit's ID ( data-ad-slot ), for example, 1234567890.
if your Google AdSense account has just approved then it might be showing blank ads space. Ads will take some times to appear until your account review process will done. You all know about Ads Blocker Task. It can disable almost all ads. Make sure that this is not the reason for showing blank AdSense Ads. Check out.
It is still possible that when you use AdSense’s responsive ad units that this happens like described. Ratan April 27, 2017 at 23:36 What does mean for “data-adsbygoogle-status=done “?
For screen widths up to 500px: a 320x100 ad unit. For screen widths between 500px and 799px: a 468x60 ad unit. For screen widths of 800px and wider: a 728x90 ad unit. To adapt this sample code for your own site: Create a display ad unit in your AdSense account, making sure you leave Responsive selected in the "Ad size" section.
Google actually has information on how to handle this - https://support.google.com/adsense/answer/10762946. There is an attribute in the ins
advert element called data-ad-status
which tells you if the advert is "filled" or "unfilled". They suggest using css to hide unfilled ads:
<style>
ins.adsbygoogle[data-ad-status="unfilled"] {
display: none !important;
}
</style>
And if their ad fails to find anything for your page, you can also replace it with your own image wrwapped in a link like so:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-1234567890"
data-ad-slot="1234567890">
<a href="/page"><img src="/backup.jpg" width="300px" height="250px"></a>
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<style>
ins.adsbygoogle a {
display: none !important;
}
ins.adsbygoogle[data-ad-status="unfilled"] a {
display: block;
}
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With