3

I have some problems when trying to integrate Google Adsense to my Weather Website.

  1. The google banner is running but not well. Sometimes, it doesn't show anything except for a blank banner. Like in this pic: Picture

  2. The first problem leads me to think about hiding the banner when there's no ads loaded. I found a solution which is adding data-ad-format="auto" to the banner tag. But I need to customize the banner dimension for the mobile. If I use data-ad-format="auto", I will not be able to customize the dimensions of the banner.

Does anyone has a solution for this? Hiding the banner when there's no ads?

Thank you very much!

Charles
  • 4,372
  • 9
  • 41
  • 80
Mavisss
  • 41
  • 3
  • Could you put it in a div and hide the entire div using JavaScript if the advert isn't there using display:none in the CSS? – party-ring Mar 21 '19 at 10:35
  • How do you check if the ad is there or not? The banner tag is still there, just there's nothing in the body tag, which is inside the banner(iframe) tag. I cannot use css selector to the body because of the structure iframe #document >html>body – Mavisss Mar 21 '19 at 10:41
  • Google will try to collapse the ad unit if no ads match by default. Can you check your settings for that ad unit? Alternatively, you can supply an image to show in the ad's place. https://support.google.com/adsense/answer/113262 – Donovan McMurray Mar 22 '19 at 15:57
  • Any updates? I have the same issue. We have a working solution for our clients using googletag.pubads().collapseEmptyDivs(true), but it's just for www.googletagservices.com. Any similar solution for Google Adsense? – Sandro May 26 '20 at 09:08

2 Answers2

2

I have had this problem for quite a while, the first ad unit above the fold does not collapse (with collapse set within Adsense), yet the ads below the fold will collapse. I have read that it will work if you integrate it with Google Ad Manager though I haven't had time to test it yet

Ryan NZ
  • 616
  • 1
  • 9
  • 25
0

You can hide the element if no ads using this:

ins.adsbygoogle[data-ad-status="unfilled"] {
    display: none !important;
}

or only show element if there is and ad using this:

ins.adsbygoogle a {
    display: none !important;
}
ins.adsbygoogle[data-ad-status="unfilled"] a {
    display: block;
}

source: https://support.google.com/adsense/answer/10762946?hl=en

Nazarudin
  • 917
  • 8
  • 26