JS

WAYS TO DETECT ADBLOCKER IN JAVASCRIPT

(quick guide & examples)

GOOGLE ADSENSE (HEADERS ONLY) let test = new Request(   "https://pagead2.googlesyndication.com/   pagead/js/adsbygoogle.js",   { method: "HEAD", mode: "no-cors" } );

LOAD AD LIBRARY

01

TEST REQUEST fetch(test) .then(res => ALLOWED) .catch(err => BLOCKED);

"INVISIBLE" DUMMY AD <div id="ad-test" style="height: 1px; width: 1px;"></div>

CHECK IF DUMMY AD REMOVED if (document.getElementById ("ad-test").clientHeight == 0) { BLOCKED } else { ALLOWED }

INSERT DUMMY AD

02

SET "BLOCKED" STATUS <script>var blocked = true;</script>

LOAD DUMMY AD LIBRARY

03

RESULT <script> if (blocked) { BLOCKED } else { ALLOWED } </script>

MY-ADS.JS - BLOCKED = FALSE; <script src="my-ads.js"></script>

if (typeof blockAdBlock === "undefined") {   LIBRARY CANNOT LOAD, ASSUME   ADBLOCK IN PLACE } else {   blockAdBlock.onDetected(() =>   BLOCKED);   blockAdBlock.onNotDetected(() =>   ALLOWED); }

ADBLOCK DETECT LIBRARY

04