Simple way to detect ad blocking extensions/addons (and monetizing without ads)


Lately, I’ve seen a lot of people using ad block extensions/addons to block ads on the websites. Such extensions/addons reduce the clutter a bit, hence provide a better browsing experience to the user. But on the other hand, many sites solely depend on the ad revenues in order to keep them running.

In order to fix this problem, I quickly hacked a very tiny script which detects ad blocking extensions/addons. I’ve tested the script with AdBlock and AdBlock Plus extensions and it worked fine.

Here are the steps to detect ad blocking extensions/addons:

  1. Create a file called adsense.js with the follwing line and include it in head section of your webpage:
    var grgjeka = true;

    Naming the file adsense.js will trigger  ad blocking extensions/addons to block the file. You can rename the variable to any random string.

  2. Add the following lines of code in another javascript file (name it main.js and it won’t trigger the ad blocking extension/addons) or within script tags in the webpage itself, to detect if the file was blocked from loading:
    if(typeof grgjeka === 'undefined') {
        //show donate button, affiliate links, popups or whatever you want to show.

    The above code snippet simply checks whether the variable was defined or not. If it wasn’t, it simply means adsense.js was blocked by the extension/addons.

If you are visiting this page with an ad blocking extension/addon installed in your browser, you might be seeing a donate button and a madmimi banner with my affiliate link (screenshot below).

Sidebar when ad blocking extension installed

Sidebar when ad blocking extension installed

Leave a Reply

Your email address will not be published. Required fields are marked *