Resource icon

How to collapse empty blank spaces when no AdSense ad is available

djbaxter

Well-known member
I don't know how to create add-ons in Xenforo.

Plus see my update: this script, although recommended by Google, does not work or has stopped working.
 

Kirby

Well-known member
collapseEmptyDivs() is for ads (including AdSense ads) delivered through Google Ad Manager (previously called Doubleclick for Pusblishers or DFP in short), it will not work for direct Google AdSense ads neither manual nor auto-ads.

It does work just fine for DFP ads, though I am not sure if it is a good idea to use it is it most likely would increase CLS
 

djbaxter

Well-known member
I'm afraid so. Since it was a Google recommendation, I tried it on a couple of WordPress and Xenforo sites. It did seem to work initially on a WordPress site but then stopped.
 

Kirby

Well-known member
@Kirby
is the conclusion that nobody has been able to get this to work?
Please read my previous post; this code is for Google AdManager/Doubleclick for publishers (DFP) and does work just fine for that. It does not work for pure AdSense.
 
Last edited:

djbaxter

Well-known member

I would like to know how I can get the AD space to collapse when there is no fill, either using Javascript or CSS. I found old articles, but the code doesn't match what google tells me to put on my website.

I surrounded the ad space in a div, but it just leaves a large white space when nothing shows up. I have service workers so that the user can use the website while offline. I would like the ad space to collapse so that there is more room for content. This is what I have pasted into the my website.
Platinum Product Expert Gracey

8/11/19


AdSense is already doing that - though I'm not sure if it's rolled out to all accounts yet.

Simplifying "If no ads available"
We're continuously working to increase the quality and safety of our ad network and reduce the number of malicious ads that enter the AdSense network. As a result, we're removing the "If no ads available" option and we'll be defaulting to collapsing the ad space or showing a blank space instead. If your current setting is a color or another URL, it will be updated in the near future.

https://support.google.com/adsense/answer/9193354
Except of course it isn't happening.
 

king8084

Well-known member
Please read my previous post; this code is for Google AdManager/Doubleclick for publishers (DFP) and does work just fine for that. It does not work for pure AdSense.
AdSense is what was in question here (at least from my side)...this is strange.
 

djbaxter

Well-known member
I just came across this by @bzcomputers

Restrict AdSense ads

  1. Replace the list at AdminCP >> Setup >> Advertising
  2. Scroll down to "Prevent ads showing in these templates" and replace the existing shorter list with the lost in the first link below.

I just applied this to two Xenforo 2.2.1 forums now and so far it has removed the large blank space on those pages.

This might be helpful for also avoiding AdSense violation warnings:

 
Top