Forum Moderators: martinibuster

Message Too Old, No Replies

How to Deliver Backup Ads

         

Etcetra

11:55 pm on Feb 14, 2020 (gmt 0)

5+ Year Member



Adsense removed preferenced to offer backups ads.

When Adsense cannot deliver an ad it results in a large blank space the same size of an ad or nothing at all.

I have not found any javascript or other code I can use to check if an ad will actually be rendered or not and provide a backup ad if its not.

I have a html division using the class name of "adsenseads" with Adsense code it in. I placed the following code just before the closing body tag to test if an ad was delivered to the division and then a backup ad if it was not. For testing purposes I am just using the phrase "BACKUP AD CONTENT HERE" rather than actual code for another network.

This code fails because Adsense is delivering the same code to the division regardless of whether it actually shows an ad, shows a blank space, or shows nothing at all. There is nothing in the code delivered by Adsense that you could flag in order to test if an ad will actually be delivered. I believe this is intentionally designed this way by Google to prevent you from delivering a backup ad.

This is unacceptable as I am not having a large unsitely blank space on my site. Nor I am going to waste space on my site for non performing Adsense ads as I don't work for free. Google on the other hand does not appear to care at all - they've not even updated their own help system - it still instructs you to create a backup ad via a preference that they removed.

<script type='text/javascript'>
<![CDATA[

// Run when the DOM content is loaded
document.addEventListener('DOMContentLoaded',function(){
// AdSense ads lazy load, so they can't be examined right away
setTimeout(function(){
// Search the DOM for ad slots assuming they all have <div class=adsenseads> around them
var x=document.getElementsByClassName("adsenseads")
for(var i=0;i<x.length;i++){
// See if adsense loaded an ad by checking for an iframe
if(x[i].innerHTML.search(/iframe/i)==-1){
// No ad loaded
x[i].innerHTML="BACKUP AD CONTENT HERE";
}
}
},3000); // 3000ms or 3 seconds
});

]]>
</script>


If you add the code below above the closing body tag it will always return the same type of code from Adsense regardless of whether an ad is shown or not.

alert(document.getElementById(&quot;adsenseads&quot;).innerHTML);
</script>


I host my site on Blogger using a csutom Google .com domain.

lammert

9:55 am on Feb 15, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld Etcetra!

It seems a deliberate decision by Google to not show any backup ads as mentioned in this help article Recent updates to ad units June 17, 2019 [support.google.com]. According to their support pages, it is to prevent malicious ads to be shown as a replacement for AdSense ads.
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.

If you use responsive ads, the Google AdSense code is not responsible for creating the space to display the ads which can be a reason to not collapse the space but showing a white background instead. You may want to test if fixed-sized ads give the same behavior. Their help text which I quoted above still collapses ad space in some circumstances.

Besides this, the only option is to check with a background JavaScript task to see when the DOM loading has been completed and if there is ad content in the AdSense spaces. If not, that JavaScript code may decide to load ads from other sources. But those ads will be loaded much later than the page itself.

Dimitri

11:35 am on Feb 15, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



we'll be defaulting to collapsing the ad space or showing a blank space instead.

Adsense will "collapse" "empty" ad space, only if they are not in the view port, at the moment of the loading.

In other words, an "empty" ad space above the fold, will not be collapsed, excepting if the user scrolled down the page, faster than the ad loading, of if an anchor link was used to jump directly lower down the page.

In case of collapsing, you just have to check the height of the container, to know if it 's collapsed or not.

For blank space, I didn't yet come up to a solution. If you inspect the DOM, you'll see that Adsense is modifying all parents of the ad container and inject CSS code, for the height of elements, preventing you to detect anything. Adsense is also using iframe, inside iframe which prevents "us" to read anything from them.

A trick would be to place all your ad slots at the end of the page (as we were doing before async code), like that all blank slots will be collapsed. Then you can position the ads inside the page in their final place, using javascript (changing the parents). However, it might be against Adsense TOS.

Etcetra

1:27 pm on Feb 15, 2020 (gmt 0)

5+ Year Member



I've modifed an existing Blogger template so that it no longer looks like a Blogger site. There are two occurences of the tag
<data:post.body/>
in the teplate. To have an ad appear below a post's main content and above the footer one places the ad code below each of those tags. Placing ad code above each of those tags makes it appear between the post's title and main content.

To make sure it apepars only on post pages Blogger conditional tags are added.

       <b:if cond='data:view.isPost'>
<div class='adsense-ads' id='adsenseads'>

<script async='async' src='https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'/>
<ins class='adsbygoogle' data-ad-client='ca-pub-XXXXXXXXXXXXXXXX' data-ad-format='fluid' data-ad-layout='in-article' data-ad-slot='XXXXXXXXXX' style='display:block; text-align:center;'/>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</b:if>


On a desktop my site's main content has a max width of 1000px wide. Any responsive ads that do appear are typically 1000px x 200px using on a desktop.

All of my posts have enough content to make sure the ad is below the fold when the page is loaded. Leaving the ad above the fold while the page fully loads produces less blank spaces. Blank 1000px x 200px areas are still being rendered on some pages as well as no ads.

I've attempted to obtain the height before. I placed the code which attempts to obtain the height in a SetTimeOut function just above the closing body tag but it always returns the height as 'undefined'.

I have found Adsense to be too unreliable at providing content. I think Adsense's claim that they made the move to block backup ads as a way to protect users is empty. I signed up for an account with AdCash which is listed as a certified Google partner and their first banner ad was to the website of the publisher of the scam product MacKeeper This company has fined by government agencies for wrongdoing. When you complain to Google about this then they make excuses about not verifying their partners. In other words being a certifed Google partner means nothing at all.

levo

12:42 am on Feb 16, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Create an 'Ad Manager' ad unit, with Adsense option (Maximize revenue of unsold inventory with AdSense) turned on. You can then create 'House' campaigns that fill those units when Adsense is empty.

I wouldn't attempt to try to detect and 'overwrite' adsense placements.

Etcetra

6:36 am on Feb 16, 2020 (gmt 0)

5+ Year Member



Thanks for the suggestion.

Ad Manager's interface presents an almost endless group of settings and preferences which are in turn linked to an almost endless stream of so called help documents which are often out of date. Google's help system still says you can use backup ads with Adsense and explains how even though that feature has been removed. Its like reading a 400 page computer manual from 1979 to accomplish a 5 minute job that should be self-explanatory from the way the interface and hep system are designed. I find it way too complicated to use.

I am not a fan of Google products as I find they go against common sense and ergonomics. They don't; for instance, allow users to sort photos by file name in Google Photo ablums even though millions of their users are interested in this feature - a feature found on personal computers for decades. Thats alone is wasting millions of man hours each year.

NickMNS

7:35 pm on Feb 16, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am not a fan of Google products

Then use a non-Google adserver like OpenX or any other.

Lexur

7:58 am on May 8, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Etcetra, thanks for your script.

However, I am unable to make it work at all.

I just copypasted the code in a local .html file into an "adsenseads" div, where Adsense Ads will not be shown, and expected to see that "BACKUP AD CONTENT HERE" but nothing happened.

Is this "trick" still working?
Did it worked anytime for anyone else?

Lexur

7:58 am on May 10, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I finally made it work BUT I always get the backup ads because I use OpenX to display ads and they always come into an iframe , so there must be something in the Google's code to trigger the backup ads, and my lack of Javascript knowledge prevents me from discover that element.

Could anyone take a look there?

not2easy

1:25 pm on May 10, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The script here is written for Blogger specific use and interlaced with Blogger specific elements and Blogger conditional tags - which may or may not have the needed attributes on a non-Blogger page. Use of an "adsenseads" div by itself may not have the necessary attributes to function with the script as expected, the definitions are not included.

For example, the use of
'data:view' 
is defined in the Blogger template but unless your use is also defined the same way, then just using the
<b:if cond='data:view.isPost'> 
element without its definitions and functions may not trigger the script as expected. I hope this is helpful.

Lexur

4:05 am on May 11, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you, not2easy.

It seems I should look for another solutions.