AdSense ad units update after the ad request has been made to indicate if the ad unit was either filled with an ad creative or left unfilled. You can check what percentage of your ad units are unfilled by reviewing your average coverage in AdSense reporting.
After an ad unit has finished requesting an ad, AdSense adds a parameter to the <ins>
element called data-ad-status
. Note: data-ad-status
should not be confused with data-adsbygoogle-status
, which is used by our ad code for ads processing purposes.
Depending on whether or not an ad was returned, this parameter will update to one of the following:
data-ad-status="filled" |
An ad was returned to the ad unit and is now showing. |
data-ad-status="unfilled" |
No ads were returned and the ad unit is empty. |
What AdSense does with unfilled ad units
When AdSense ad units are "unfilled
", we try to either collapse the ad unit or show a blank space. We only collapse ad units when they are not going to cause page reflow, meaning only ad units outside of the viewport are collapsed. For all other unfilled ad units, we retain the ad unit size, and instead show a blank space.
How to hide your unfilled ad units
(advanced) You can decide to augment this behaviour either using CSS or JavaScript. For example, if you want to hide all unfilled ad units, you can use CSS to apply a display: none !important;
style to the element.
Example 1: Hiding unfilled ad units using CSS
You can add the following CSS style to your page to automatically hide unfilled ad units:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
ins.adsbygoogle[data-ad-status="unfilled"] {
display: none !important;
}
Example 2: Showing an image only if the ad unit is unfilled
If an ad unit doesn't show an ad, you can instead choose to show a house ad:
<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-1234567890123456"
data-ad-slot="1234567890">
<a href="/page"><img src="/backup.jpg" width="300px" height="250px"></a>
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
ins.adsbygoogle a {
display: none !important;
}
ins.adsbygoogle[data-ad-status="unfilled"] a {
display: block;
}
Alternatively, if you would prefer to use JavaScript to update your page, it's possible to use MutationObserver to detect changes in the data-ad-status
parameter and execute JavaScript code based on those changes.
Limitations
The data-ad-status
parameter is only added to ad units that exist on the top window. This means for ad units that are being served via a cross-domain window, the data-ad-status
parameter won't be added to an ad unit.
We also don't recommend loading AdSense ad units as initially hidden, with the goal of making them visible upon the data-ad-status
parameter change. If ad units aren't initially visible on the page, we may not execute the ad request for that ad unit.