0

So recently I've signed up to adsense and put in on my URL shortening project. The ad currently is displayed on the header of the site. (Above the navbar). And when users have Adblock enabled, it pretty much ruins the header part of the site.

Now I did my research, I found a topic here already, but that didn't help me at all.

If anyone has any good ways of detecting adblock, would appreciate it!

Community
  • 1
  • 1
DharmeshPHP
  • 41
  • 1
  • 6
  • How is the header ruined? Use `window.getComputedStyle` on your "ruined" node/s, if it's/they're not as expected, you know something has happened - adblock/failed to load/weird custom useragent stylesheet? – Paul S. Aug 10 '13 at 12:12

2 Answers2

1

adblock works by blocking resources from this list: https://easylist-downloads.adblockplus.org/easylist.txt

pick a file that matches the list for ex:

ad1.js

create that file and make it accessible to your site and add this code to it:

window.adblock = false;

now in your app js put:

window.adblock = true;
$.getScript("/js/ad1.js");

now when you go to show an add just check window.adblock to see if adblock is enabled.

if (window.adblock)
  console.error("adblock is enabled")
else
  console.log("adblock is not enabled show ads")
radiofrequency
  • 873
  • 8
  • 19
0
function handle_adsense_blocker() {

 if (typeof(window.google_jobrunner) == 'undefined') {

  // doesn't seem to work for opera
  if ( navigator.userAgent.match(/opera/i) ) {

   return;

 }

 // replace Adsense ads with something else

 }

}

// add this to your window load event
window.setTimeout('handle_adsense_blocker()', 3000);
Chaoley
  • 1,282
  • 15
  • 21