Google Adsense Error “TagError: adsbygoogle.push() error: No slot size for availableWidth=0 ”

后端 未结 13 1395
梦如初夏
梦如初夏 2021-01-31 08:56

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

相关标签:
13条回答
  • 2021-01-31 09:34

    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%;">
    
    0 讨论(0)
  • 2021-01-31 09:37

    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.

    0 讨论(0)
  • 2021-01-31 09:38

    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({});
      });
    });
    
    0 讨论(0)
  • 2021-01-31 09:39

    Where is your parent container? You are supposed to set width and height on the parent I think, not the actual <ins> tag.

    0 讨论(0)
  • 2021-01-31 09:42

    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.

    • Total number of ads does not exceed google's limit, which is 3 ads per page. Advertising and other paid promotional material added to your pages should not exceed your content, per Google's new policy.
    • Number of ads pushed to 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;
    }
    
    0 讨论(0)
  • 2021-01-31 09:45

    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

    0 讨论(0)
提交回复
热议问题