Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

css

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.push() error: No slot size for availableWidth=0

I tried to fix the issue by defining the Ad Sizes but still the issue is not resolved yet.

.adslot_1 { width: 320px; height: 100px; } @media (min-width:500px) { .adslot_1 { width: 468px; height: 60px; } } @media (min-width:800px) { .adslot_1 { width: 728px; height: 90px; } } @media only screen and (min-width:800px)and (max-width:3000px) {     #topbanner {         width: 640px;         height: 90px;     } } 

Well, this is the actual Google Adsense Google Code that I've used (for security reasons I've remove pub-id and ad-slot.)

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- articles(auto) --> <ins class="adsbygoogle adslot_1"      style="display:inline-block;"      data-ad-client="ca-pub-[MY_AD_ID]"      data-ad-slot="AD_SLOT_NOS"      data-ad-format="rectangle, horizontal"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> 
like image 484
Raag Singh Avatar asked Nov 01 '15 17:11

Raag Singh


1 Answers

I used:

window.onload = function() {     (adsbygoogle = window.adsbygoogle || []).push({}); } 

My site was loading pages in a special way, making heavy use of AJAX, so it had to be this way. Hope this helps someone.

EDIT 2018: I feel like I should mention now that the preferred way to do this would be with window.addEventListener( 'load', ... ), instead of the old method of window.onload = ...

like image 114
Sorin C Avatar answered Oct 05 '22 07:10

Sorin C