No matter how you feel about ad blockers, it’s useful as a website owner to know what percentage of your users have one installed. Estimates range from 10% – 40%, and may be even higher on sites with a sophisticated user base.

Fortunately, it’s pretty easy to detect whether an ad blocker is present. There are various technologies, but as a common denominator they all tend to hide any DIV element named something like “ads” or “adsense”. So to detect the use of an ad blocker, just create a div that looks like an ad container and then check whether it has been set to display:none.

Here is a simple script you can add to your site that does just that. This assumes you have Google Analytics installed. It will create a new “Event” in Google Analytics with a Category called “UserPrefs”, with an Action called “AdBlock”, and possible values of “Yes” and “No”. Of course, you can change these names if you want. One cool thing about Google Analytics is you can see this number in real time!

<script>
(function () {
	document.write('<div id="adsense" style="visibility:hidden;">adsense ad</div>');
	var detect = function() {
		setTimeout(function() {
			var detected = 'No';
			var elt = document.getElementById('adsense');
			if( ! elt || elt.innerHTML.length === 0 || elt.clientHeight === 0 ) {
				detected = 'Yes';
			}
			elt.style.display = 'none';
			if(typeof ga === "function") {
				ga('send', 'event', 'UserPrefs', 'AdBlock', detected);
			}
			else if(typeof _gaq != "undefined") {
				_gaq.push(['_trackEvent', 'UserPrefs', 'AdBlock', detected]);
			}
		}, 2000);
	}
	if(window.addEventListener) {
	    window.addEventListener('load', detect, false);
	} else {
	    window.attachEvent('onload', detect);
	}
})();
</script>

And here is an Google Analytics screenshot taken from one website that uses this script. You can that that approximately 40% of users have an ad blocker installed.

how-to-detect-adblock

I’m very interested in your experiences here. If you find this script useful, please feel free to share your results privately via email or publicly as a comment.

** Note that this method establishes a lower bound. If you are seeing 20% in Google Analytics, that means at least 20% of users have ad blocker, but the real number could be a bit higher. This script is not particularly fancy, but it basically works. If you want a more sophisticated approach, there are companies that specialize in this.

Drop Us a Line

We’re dedicated to working with the hungriest minds in our field. If you’re involved with digital content production or digital advertising and marketing, we’d love to hear from you. Big, small, experienced or beginner, please feel free to get in contact if you think we can be of service.

Say Hello