Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if my AdSense ad is blocked?

If user has some kind of ad blocker installed, ad blocker will of course remove all ads from my website, and it leaves empty spaces where the ads used to be. I would like to use that empty space by putting some other content in it, like links to most important pages of my website, to do that I need to detect if AdSense javascript is loaded.

Methods that I have tried so far:

if (!document.getElementById("google_ads_frame1"))
{
}

and:

if (typeof(window.google_render_ad) == "undefined")
{
}

Both of those seem to fail in certain situation, for example if browser downloads AdSense javascript files a bit slower, it will execute above mentioned code before AdSense code is loaded and I end up hiding ads for users that don't even have ads blocked.

Do you have any suggestions on how could I make sure that my code is run after AdSense? Or some other way of detecting that AdSense scripts are not loaded?

like image 515
Igor Jerosimić Avatar asked Feb 19 '11 20:02

Igor Jerosimić


People also ask

How do I know if my site is banned from AdSense?

Google AdSense sandbox: Simply go to this link, add the domain name you want to check for, select the region and click on peview ads. If you see all the ad spots are blank, that means the AdSense account is banned for a particular domain.

How do you find out what is blocking ads?

You can use AdBlock's resource page to see all the requests a website makes and how AdBlock deals with them. You can also use it to create exceptions, filters that customize what resources AdBlock blocks or hides. A resource is anything a web page asks to download to your browser.

How do I unblock AdSense?

In the appeal form, provide the email address that's associated with your disabled Google AdSense account. This will help us locate your account and reduce delays in processing your appeal. Tell us what changes you'll make for the future.


4 Answers

If using the new AdSense code, you can do an easy check, without resorting to content or css checks.

Place your ads as normal in your markup:

<ins class="adsbygoogle" style="display: block;"
   data-ad-client="ca-pub-######"
   data-ad-slot="#######"
   data-ad-format="auto"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

Then you call the adsense code at the bottom of your page (note do not use the "async" flag when calling the adsbygoogle.js script):

<script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

Then add this little snippet of code below that:

<script>
if (!adsbygoogle.loaded) {
   // do something to alert the user
}
</script>

AdSense always creates/sets the flag adsbygoogle.loaded to true when the ads are loaded. You could place the check in a setTimeout function to delay the check by a few seconds.

like image 123
Troy Morehouse Avatar answered Sep 21 '22 03:09

Troy Morehouse


This ultra-lightweight method seems to be infallible and is agnostic to all ad networks.

Place a file call ads.js in your root folder and add this line inside it:

var can_run_ads = true;

Adblock won't allow a file named ads.js to be loaded. So, just place this code before </body>

<script src="/ads.js"></script>
<script>
if(window.can_run_ads === undefined) {
    alert('Please Disable Adblock, ****** ******!');
}
</script>';

I strongly recommend to redirect the user to a page that has instructions on how to remove Adblock.

like image 31
Andres SK Avatar answered Sep 20 '22 03:09

Andres SK


Run this code on the window.onload event. window.onload event is fired when the page has completed loading.

window.onload = function() {
  // your checks
}

If you're using jQuery, use

$(window).load(function() {
  // your checks
});
like image 22
Dogbert Avatar answered Sep 17 '22 03:09

Dogbert


I suggest you use FuckAdBlock to detect if AdBlock is activated. If this is the case, you are free to add as many html in your page you want.

See the documentation for examples: https://github.com/sitexw/FuckAdBlock

like image 20
SiteXw Avatar answered Sep 20 '22 03:09

SiteXw