• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created about 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AdBlock Detection Scripts

Introduction

Javascript to detect the presence of behavior associated with ad blocking during delivery of a page.

Operation

The JavaScript (adblockDetector.js) has been tested to detect the behaviors associated with ad blocking in the following web browsers:

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer (8+)
  • Safari

The script does this by creating a set of DIVs that are likely to be hidden by browser-based ad blocking tools.

Additional tactics that are not yet included in this script:

  • URL bait. Allow the detection of network-based ad blocking.
  • Dynamic bait modification. Update DIV and URL attributes based on the existing blocking lists (Easylist and so on) to make detection more robust.

Installation

Download the desired detection script and add it to your website. There are a few different ways to include JavaScript into HTML.

Script Name Description
adblockDetector.js Adblocker detection script without Google Analytics module
adblockDetectorWithGA.js Adblocker detection script with Google Analytics module

With AdBlockDetectionWithGA.js you are asked to mention your GA tracking id into the script on line no 82. When you are referencing this script, it tracks certain events regarding AdBlock on user browser. You can view the details in the Google Analytics dashboard. Here is how to check whether user are using any adblock or not.

Setting up Google Analytics

Firstly, we would suggest you create a different GA-Tracking id so that it might not interfere with your pageviews. Follow below steps for GA on Use of Adblock.

  • Sign into your Google Analytics account -> Go to your site -> Go to “Reporting” tab -> click “User Explorer” under Audience.
  • Click on “Add new segment” -> “New Segment” -> Give Segment name (ex: ‘Adblock Detected’) -> Click on “conditions” under Advanced section.
  • Click on Sessions and select Users (You can create a different one for sessions too.)
  • Click on the first Drop Down -> Click on “Behavior” ->Select “Event Label”.
  • Click On the Text box: Type event label as below.
  • Event Label- “div hidden” – this will give you all users with Ad block enable/found.Now your one segment with Users who use ad block is ready.
  • Repeat all above steps with Below event label for users who do not use ad block.
  • Event Label- “div visible” –this will give you all users with ad block disabled/notfound.

Unfortunately we have not figured out yet how to put it to dash board. So next time when you go to GA, you can go to User Explorer -> click Add new segment. And you will find the segments you previously created(i.e one for adblock Detected users and one for ad block NotDetected users.). You can select them and click on apply to see reported data.

It should look like below image.

alt text

Inline

This is the recommended method of inclusion. The functions contained in the chosen detection script should be included directly into the HTML of the parent frame.

Do this by wrapping the content of the selected code in script tags in the delivered HTML.

External Script File

It is possible to host the selected code on your web server as an independent file, and to reference this file from the delivered HTML.

If you use an external script file, it can be blocked by ad blockers. Using a different name for the file will reduce the probability that it will be blocked by generic filters.

Other Methods

It is possible to integrate the functions from the selected code into an existing script library, hosted as an external script file. Doing this may result in reduced site functionality for visitors using ad blockers that are trying to avoid detection, if the ad blockers block the entire external script file.

Configuration

@prop flags

Option Type Description
debug Boolean Indicates additional debug output should be printed to console
found String (@function) Function to fire if adblock is detected
notfound String (@function) Function to fire if adblock is not detected. Note that this will fire each time adblock is not detected, and should provide input to action taken only after “complete” is detected.
complete String (@function) Function to fire once testing is complete.

The test result (boolean) is included as a parameter to callback example:

window.adblockDetector.init(
        {
          found: function(){ ...},
          notFound: function(){...}
        }
      );

Usage

Add the below code in the HTML page.

<script src="./adblockDetector.js"></script>
	<script>
	// Configure the adblock detector
	(function(){
		var enabledEl = document.getElementById('adb-enabled');
		var disabledEl = document.getElementById('adb-not-enabled');
		function adBlockDetected() {
			enabledEl.style.display = 'block';
			disabledEl.style.display = 'none';
		}
		function adBlockNotDetected() {
			disabledEl.style.display = 'block';
			enabledEl.style.display = 'none';
		}
		
		if(typeof window.adblockDetector === 'undefined') {
			adBlockDetected();
		} else {
			window.adblockDetector.init(
				{
					debug: true,
					found: function(){
						adBlockDetected();
					},
					notFound: function(){
						adBlockNotDetected();
					}
				}
			);
		}
	}());
	</script>

Add below code in the body of the HTML page

<div class="center">
<h5 class="bg-success" id="adb-not-enabled" style="display: none;">AdBlock is disabled</h5>
<h5 class="bg-danger" id="adb-enabled" style="display: none;">AdBlock is enabled</h5>
</div>

Contributing

Fork it! Create your feature branch: git checkout -b my-new-feature Commit your changes: git commit -am 'Add some feature' Push to the branch: git push origin my-new-feature Submit a pull request

FAQ

  • The script will not work locally. The page should get served from the server via http
  • Currently the “baits” or “honey pods” used in the Javascript are hardcoded @ #218. If you want to update the file with new baits update the line #218
  • Use the sample file test.html find in the repository. Host the file on HTTP server eg. apache server and request the file in browser via http with adblocker on/off.

More Repositories

1

GDPR-Transparency-and-Consent-Framework

Technical specifications for IAB Europe Transparency and Consent Framework that will help the digital advertising industry interpret and comply with EU rules on data protection and privacy - notably the General Data Protection Regulation (GDPR) that comes into effect on May 25, 2018.
864
star
2

openrtb

Open RTB is a protocol for real time bidding on digital media
398
star
3

VAST_Samples

Sample VAST Tag Use cases
183
star
4

adstxtcrawler

A reference implementation in python of a simple crawler for Ads.txt
Python
160
star
5

vast

Video Ad Serving Template (VAST)
HTML
112
star
6

iabtcf-es

Official compliant tool suite for implementing the Transparency and Consent Framework (TCF) v2.0. The essential toolkit for CMPs.
TypeScript
109
star
7

AdCOM

Advertising Common Object Model (OpenMedia)
101
star
8

safeframe

SafeFrame reference implementation official mirror from SourceForge
JavaScript
92
star
9

Consent-String-SDK-JS

Transparency and Consent Framework v1.1 Consent String SDK - javascript
JavaScript
89
star
10

openvv

ActionScript
81
star
11

USPrivacy

Technical specifications to support US Privacy initiatives, starting with CCPA (California Consumer Privacy Act)
67
star
12

openrtb2.x

OpenRTB 2.x specification, from 2.6 onward
67
star
13

taxonomy

Machine-readable Taxonomies with ID mappings
64
star
14

Open-Measurement-JSClients

JavaScript
53
star
15

SIMID

Secure Interactive Media Interface Definition (SIMID)
HTML
47
star
16

iabtcf-java

Transparency and Consent Framework v2.0 Library - Java
Java
34
star
17

flex-ad-testing

Helper code and samples for testing and using the new IAB Flexible ad formats
HTML
34
star
18

Global-Privacy-Platform

IAB Tech Lab Global Privacy Platform specification
30
star
19

Consent-String-SDK-Java

Transparency and Consent Framework Consent String SDK - Java
Java
30
star
20

vmap

Digital Video Multiple Ad Playlist
25
star
21

ads.txt-parser

A reference implementation of ads.txt parsing code (currently focused on app-ads.txt)
Go
25
star
22

AdManagementAPI

Ad Management API (creative approval specification in OpenMedia specification stack)
24
star
23

OpenDirect

20
star
24

CCPA-reference-code

workspace for CCPA publisher code dev
HTML
19
star
25

dynamicContentAdsSchema

Dynamic Content Ads Schema
19
star
26

openvv-html

OpenVV project to provide viewability data and API to HTML5 based video
JavaScript
19
star
27

PrivacyChain

HTML
15
star
28

openrtb-model

Data models for 2.X and 3.0
Java
15
star
29

iabtcf

Vue
14
star
30

MRAID-3.0-Compliance-Ads

JavaScript
12
star
31

openrtb3-converter

Java
12
star
32

Consent-String-SDK-Swift

Transparency and Consent Framework Consent String SDK Swift
Swift
11
star
33

daast

8
star
34

Open-Measurement-ReferenceApp-iOS

Swift
8
star
35

HTML5-AdValidator

8
star
36

ads-cert-openrtb3-verifier

Java
5
star
37

vpaid

3
star
38

Consent-String-SDK-Scala

Transparency and Consent Framework Consent String SDK Scala
3
star
39

Consent-String-SDK-Android-

Transparency and Consent Framework Consent String SDK
2
star
40

Consent-String-SDK-C

Transparency and Consent Framework Consent String SDK C
2
star
41

OpenDirect-Spec-Review

2
star
42

mraidadtester-android-mobileapp

MRAID ad unit tester for Android
Java
1
star
43

safeframe-contrib

Community contributions and extensions to SafeFrame
1
star
44

test-transfer

An /empty/ repo to test transfers (bar readme.md)
1
star
45

OMSDK-KnownIssues

1
star