1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Solution for availableWidth bug in responsive ads

Discussion in 'AdSense' started by deathshadow, Dec 18, 2015.

  1. #1
    I don't know how many of you are trying to use the responsive advert code, where you set data-ad-format="auto", or "vertical", or "horizontal"... It works perfect in Chrome and other blink browsers (duh) and even IE likes it...

    Bug Firefox will from time to time completely drop the ball and pop that error. The problem occurs 95%+ of the time when the script is already in your cache, letting the "push" of the empty object occur on window.adsbygoogle instead of creating a new empty array.

    I'd been struggling with this one for a while, and was ready to rip the ads out completely since I don't trust advertisers in the first blasted place... (my even having ads is an experiment)

    The "recommended" fix you'll find is to fix the size of the container -- that made me laugh as that completely defeats the point of even having data-ad-format="auto". There had to be a bettter way, and that it worked when cache was empty gave me that "EUREKA" moment.

    Take the default code:
    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-123456789" data-ad-slot="123456789" data-ad-format="auto"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
    Code (markup):
    As cache clean it was working two-thirds the time, adsbygoogle.js cached it wasn't I figured it HAD to be an execution order issue.... Is that push going to windows.adsbygoogle the problem? What if we flip it around so that the empty array HAS to exist before the script is loaded?

    
    <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-123456789" data-ad-slot="123456789" data-ad-format="auto"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    Code (markup):
    WORKS EVERY BLASTED TIME!!! After searching for other cases of this problem I found a good number of testcases and this simple re-arrangement fixes every last one of them!

    Really though I wonder what the *** that push is even for, since their script should be waiting for onload in the first place and just hooking INS by classname -- but I gave up trying to make sense of their massive bloated scripts ages ago.
    SEMrush
    So, just thought I'd share in case anyone else is struggling with this.
     
    deathshadow, Dec 18, 2015 IP
    th.sigit likes this.
    SEMrush