https://github.com/blueberryapps/detect-adblock
  
  
    Get information about whether the user has enabled AdBlock 
    https://github.com/blueberryapps/detect-adblock
  
adblock blueberry-opensource detector javascript
        Last synced: 7 months ago 
        JSON representation
    
Get information about whether the user has enabled AdBlock
- Host: GitHub
- URL: https://github.com/blueberryapps/detect-adblock
- Owner: blueberryapps
- Created: 2017-02-23T08:44:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T16:10:34.000Z (almost 3 years ago)
- Last Synced: 2025-03-27T13:12:23.412Z (7 months ago)
- Topics: adblock, blueberry-opensource, detector, javascript
- Language: JavaScript
- Homepage:
- Size: 201 KB
- Stars: 24
- Watchers: 28
- Forks: 2
- Open Issues: 5
- 
            Metadata Files:
            - Readme: readme.md
 
Awesome Lists containing this project
README
          # Detect AdBlock [](https://dependencyci.com/github/blueberryapps/detect-adblock)
```
yarn add detect-adblock
```
DetectAdbblock is a library which recognizes using of ad blocker in a browser. You can use it in case you want to show advertisment towards users or just run important script which are beign blocked.
# Motivation
This library is inspired by [BlockAdBlock project](https://github.com/sitexw/BlockAdBlock). Main changes are that this library is simplified, completely written in ES6 and contains tests written in Jest.
# How to use
To use Detect AdBlock you need just to import `DetectAdblock` class to your project and then use it as a standard javascript class.
## Constructor
* `timeout` specifies number of `ms` to run check for, default is 1000.
* `enabledHandler` is a callback which is called when no ad block is recognized.
* `disabledHandler` is a callback which is called when no ad block is not recognized.
## Methods
* `startChecking(count)` is a method which starts checking for ad blockers. Count is the number of checks in one run. Default is 5.
# Example
```js
import DetectAdblock from '@blueberry/detect-adblock'
const onEnabled = () => console.log('ENABLED');
const onDisabled = () => console.log('DISABLED');
const check = () => {
  // It is important to check wheter the script is rendered in the browser.
  if (!process.env.IS_BROWSER) return;
  const detector = new DetectAdblock(500, onEnabled, onDisabled);
  detector.startChecking(3);
  return;
};
```
# Browser compatibility
The package should work in all modern browsers including IE8+.
## Made with love by
[](https://www.blueberry.io)