A tiny and simple browser library for detecting ad blocker presence on page. Do as you please once you are aware. Has no dependecies and weighs less than 1KB.
Adblock detect gives you information weather user is using adblock or not. This is done via simple javascript check - no fake network requests or iframes are created, everything is done with one little bait element that ad blocker extensions like to bite on. Once you know if ad blocker is active or not you might render some message or alter page layout in some way - no assumptions are made on our side.
We detected that you are not using adblocker. We did so by running following little snippet:
adblockDetect(function(adblockDetected) {
$('.adblockDetectedText').text(
adblockDetected ? 'using adblocker' : 'not using adblocker'
);
});
Because of nature of ad blockers test has to be asynchronous. A user provided callback is called with parameter that is either true or false.
Options can be defined on invocation via second parameter:
adblockDetect(function(adblockDetected) {
if (adblockDetected) {
console.log('Ad blocker is detected');
} else {
console.log('Ad blocker is not detected');
}
}, {
testInterval: 40,
testRuns: 5
});
If you plan to run ad block check multiple times and want to define options before all that function calls you can alter library defaults in following namespace:
adblockDetect.defaults = {
testNodeClasses: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',
testNodeStyle: 'height: 10px !important; font-size: 20px; color: transparent; position: absolute; bottom: 0; left: -10000px;',
testInterval: 51,
testRuns: 4
};
Adblock detect is packaged as UMD libary so you can use it in CommonJS, AMD or browser environment.
// if you use bundler
var adblockDetect = require('adblock-detect');
// or just using browser globals
var adblockDetect = window.adblockDetect;
For browser usage browse dist folder - if working with build tools go with src folder. Download library files from github repo, get them via bower (bower install adblock-detect) or via npm (npm install adblock-detect)