Unblocking Ads

Web sites need to be paid for. One way or another having a web site costs money. For personal sites the owner may simply bear the cost of the site because they want to share something with friends and family. Big companies may consider their web site to be a form of advertising and pay for it out of their advertising budget.

With companies where the web site content is what they are "selling" they can't just write off the cost of running the site. In this case the site is the business and they need to at least make enough money from it to cover the cost of having the site and to make some sort of profit. The most direct way to do this is to set up a subscription service to the main content of the site and only allow those who have paid for access to see those portions of the site. This model works best when you have premium content not readily available from other sources.

For the vast majority of sites there are alternative places where people can obtain what is basically the same web content (worded differently depending on which author wrote it but still basically covering the same material). For these sites to make the money to cover the cost of having the site they generally need to use advertising. This means that the advertisers pay for the site in return for having their ads displayed and the readers get to see the content without having to pay for it.

Of course in this case the readers do have the ads displayed on the page. For some readers the idea of paying to read content from a web site by having ads displayed is unacceptable and there have been various solutions developed to allow these people to steal the web content rather than paying for it by viewing the ads (stealing in this case meaning reading it without any form of payment meaning that the owner is paying to deliver the content to you without you providing anything in return). Note that viewing the ads and not deciding to buy (or even click on them) is perfectly satisfactory and a part of the way this particular business model works. Stripping the ads out of the page so as to view just the content without paying for it is not.

The simplest way to hide most ads is to simply turn off JavaScript for the page. If this is done then only those ads actually embedded into the HTML itself will be visible. Now some visitors have legitimate reasons for having JavaScript turned off and so this by itself is not an indication that the person is trying to steal the content. In any case if your site uses progressive enhancement (as is appropriate for this type of site) these readers will miss out on many of the more advanced features of your site and so not costing as much as those with JavaScript enabled.

Those who are deliberately setting out to force you to pay for the delivery of your content to them without them giving anything in return are those people who install ad blockers in their browser. One way around these is to use non-standard ads embedded directly into the web page itself (which also get around JavaScript being turned off) but this means finding the advertisers yourself or relying on them to find you. In most cases using an ad service provider is the only way of getting sufficient ads to pay for the site and these are what the adblock scripts primarily target.

Some adblockers will allow you to submit your web site for review by them. If they consider your ads to comply with what they consider to be acceptable then they will not block ads on your site unless the person using their script specifically adds your site to their block list. Even if you reduce the ads to get an acceptable outcome for one such script this doesn't prevent other scripts from continuing to block your ads or for those using the adblocker that found your ads acceptable from deciding to block them anyway. Either way it is still someone else who has control over how easily your content can be viewed without the ads that are paying for the site.

So is there anything that can be done about this other than switching to some other payment model? Well these adblocker scripts are removing the ads from the page source and so we can use JavaScript to test if the ads are there and if not then take some action. This doesn't prevent them from turning JavaScript off (if they know how - which many don't) or having them leave to read equivalent content somewhere else. If they go somewhere else then at least they are costing some other business money rather than yours.

So how do we go about detecting that the ads on our site have been blocked? Well we can add a script to the page that runs after a couple of seconds delay (so as to provide time for the adblocker if any to block the ads) that tests to see if the ads are blocked. Just exactly how you test will depend on the ad service you are using so let's use Google AdSense as an example as that is a fairly common one for people to use. The current AdSense script uses ins tags with a class of adsbygoogle on it so we'll test the content of those tags in the page to see if the ads have been blocked. The following script waits until two seconds after the page has finished loading and then tests the first of these ins tags for content other than whitespace. If all it finds is whitespace or nothing at all then the ads have been blocked (assuming that Google is able to deliver an ad to the page - and I haven't seen a situation where the ads have been live for more than a few minutes without Google finding something to display). If the ads have been blocked then the following code forces the empty ad block to display with some text content. You can get this code to take whatever action you prefer simply by replacing or adding to those two lines of code.

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 = "You seem to blocking Google AdSense ads in your browser.";
}}, 2000);};


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow