I\'m using responsive Google Ads on my website but unfortunately it is not working all the time and most of time it is returning
TagError: adsbygoogle.pus
If you're using angular-google-adsense
, you need to remove the ad-format
tag from your adsense html block;
Wrong:
<adsense
ad-client="ca-pub-2427218021515520"
ad-slot="5093178896"
inline-style="display:inline-block;width:100%;"
ad-format="auto">
Right:
<adsense
ad-client="ca-pub-2427218021515520"
ad-slot="5093178896"
inline-style="display:inline-block;width:100%;">
It's been all day that I've tried to find a solution to the error, and I'd like to thank @Emerson Thompson for his solution!
On one environment I'm working in, I depend on the Ad Inserter Pro for WordPress plugin. It turns out that the plugin prints the HTML for all the layouts (mobile and desktop). With viewport width as a criterion, it then hides some using CSS.
When adsbygoogle.js
finds a hidden ad, it throws the TagError: adsbygoogle.push() error: No slot size for availableWidth=0
exception blocking subsequent javascript execution.
Be sure to check your ad visibility before to initialize them.
You need to remove the others that are not visible, how I use (jQuery):
$(document).ready(function(){
var $analyticsOff = $('.adsbygoogle:hidden');
var $analyticsOn = $('.adsbygoogle:visible');
$analyticsOff.each(function() {
$(this).remove();
});
$analyticsOn.each(function() {
(adsbygoogle = window.adsbygoogle || []).push({});
});
});
Where is your parent container? You are supposed to set width and height on the parent I think, not the actual <ins>
tag.
1. Make sure that the DOM is ready when pushing the ad.
Vanilla (Modern browsers only)
document.addEventListener("DOMContentLoaded", function() {
(adsbygoogle = window.adsbygoogle || []).push({});
});
In jQuery
$(document).ready(function(){
(adsbygoogle = window.adsbygoogle || []).push({});
});
In Angular
$timeout(function () {
(adsbygoogle = window.adsbygoogle || []).push({});
});
2. Make sure the number of ads you have on the page is correct.
adsbygoogle
corresponds to the number of
ads you have on page.3. For responsive units, add width and height.
Responsive ad units need a width and a height specified on the ins
element. You could do something like this:
ins {
min-width: 300px;
min-height: 50px;
}
One possible reason is that you are styling the div that contains the ad unit using a framework that creates a conflict in size specification. In my case I was using bootstrap styling which messed up my ad display.
<div id="ad1" class="row">
<!-- ad code-->
</div>
This did not work. Once I removed it:
<div id="ad1">
<!--ad code-->
</div>
it worked fine