5

I'm trying to get Adsense ads to work correctly on my site, but somehow on some pages they load inconsistently. The ads load correctly maybe 2/3 of the time, but occasionally the space just remains blank. From what I can tell, the problem is not that there is no ad available; an iframe for the ad is created, a data-load-complete="true" tag is added, but somehow the html body tag for that ad remains empty: <body marginwidth="0" marginheight="0"></body>

<ins class="adsbygoogle" style="display: block; height: auto !important; min-height: 0px !important;" data-ad-client="ca-pub-..." data-ad-slot="6818818970" data-ad-format="auto" data-full-width-responsive="true" data-adsbygoogle-status="done">
    <ins id="aswift_1_expand" style="display:inline-table;border:none;height:280px;margin:0;padding:0;position:relative;visibility:visible;width:900px;background-color:transparent;">
        <ins id="aswift_1_anchor" style="display: block; border: none; height: 280px; margin: 0px; padding: 0px; position: relative; visibility: visible; width: 900px; background-color: transparent; overflow: visible;">
            <iframe id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;border:0;width:900px;height:280px;" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" width="900" height="280" frameborder="0" src="" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" data-google-container-id="a!1" data-google-query-id="CJf52ubwxewCFQKFgwcdwIoMHw" data-load-complete="true">
                <html class=" yirjomiyii idc0_322">
                    <script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
                    <head>
                    <script>window.top.postMessage('{"msg_type":"resize-me","key_value":[{"key":"r_nh","value":"0"},{"key":"qid","value":"COCMyfTkxewCFcaadwodDGMDxA"}],"googMsgType":"sth"}', '*');</script>
                    <script>window.top.postMessage('{"msg_type":"adsense-labs","key_value":[{"key":"settings","value":"[\\\"ca-pub-...\\\",[[1]]]"}],"googMsgType":"sth"}', '*');</script>
                    </head>
                    
                    <body marginwidth="0" marginheight="0"></body>
                </html>
            </iframe>
        </ins>
    </ins>
</ins>

From what I understand, normally if an ad doesn't load, elements with the class adsbygoogle shouldn't even have any children. Has anyone come across this problem of a seemingly partially loaded ad with an empty html body? Any ideas what might cause this or how to avoid it?

1 Answer 1

2

That's normal. AdSense doesn't always returns an ad back. When AdSense didn't find any ad - it returns empty iframe like in your example. Empty slot should be collapsed if possible (note resize-me message). We don't clean up DOM (e.g. remove all ins elements and iframe) as it doesn't affect how the page looks. It would save some memory probably but these savings are tiny given that it's 3 extra DOM elements.

1
  • Thanks. I was unaware that an empty iframe is returned. In other threads on this site I got the impression in that case all elements up to adsbygoogle class would be empty.
    – CharlesT
    Commented Oct 22, 2020 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.