Display Alternate Advertisement or Content to ADBlock Users [Web Publisher Tip]

Updated on September 1, 2017

There are plenty of browser extensions out there that allows user to block online advertisements. For instance, AdBlock the most popular extension to name. Well, in the user point of you AdBlock helps user to save some bandwidth and hide unwanted disturbing ads. However if you are a web publisher, then AdBlock or Ghostery can affect your online advertising revenue.

If you are using Google Adsense to monetize your website, then there’s a simple hack that allows you display an alternate advertisement (your own advertisement image) or content to AdBlock users.

Here we go,

The idea is to find the first Adsense unit in a page and if that doesn’t load, replace that particular AD unit with an alternate content. The alternate content can be an image to promote your own content or a product. Why not, you can even request the visitor to whitelist your domain or donate. It means, displaying something is better than showing an empty space isn’t?

alternate content to adblock users

Copy and paste the below script at the footer of your website.

<script>
 window.onload = function() {
 setTimeout(function() {
 var ad = document.querySelector("ins.adsbygoogle");
 if (ad && ad.innerHTML.replace(/\s/g, "").length == 0) {
 ad.style.cssText = 'display:block !important';
 ad.innerHTML = '<img src="//techglimpse.com/images/adblock-alternate.jpg" alt="Whitelist techglimpse.com" width="300" height="250" style="width:300px;height:250px;min-height: 250px;"/>';
 }
 }, 1000);
 };
 </script>

That’s it. The above code will replace the blocked Adsense unit with an alternate image. Note, the code will work only for Adsense and it has be tweaked for BuySell Ad or Facebook.

Finally, the credit goes to Amit Agarwal for posting this tip.

Was this article helpful?

Related Articles

Leave a Comment