Detect Adblock: Our Secret Sauce

The PageFair Team Adblocking, Uncategorized

How do we do it?

We’re often asked how our adblock detection script works its magic: how do we detect that someone is blocking ads? Most people expect us to guard this secret closely, but the truth is we use an approach that’s widely discussed online. We observe what happens when a web page loads and detect the effects of adblocking plugins.

Understand Ad Blocking

In order to know what effects to look out for we need to understand how adblock stops ads from loading. The first technique used to block ads is to intercept requests from the browser to particular domains or for particular files. Most publishers use hosted ad servers that operate from well known domains; for example Google’s display ads are served from doubleclick.net. The adblock community maintains ‘filter lists’ of these domains that are updated regularly with the latest ad server domains. Filter lists also name particular files for which requests should be blocked regardless of domain; for example any javascript file called ads.js.

The second technique used to block ads is to hide ad-related page elements based on css rules. Publishers carefully design their web pages with space for both content and advertising, but when ads are blocked this could leave large, empty areas on screen. The adblock community’s filter lists specify page elements that should be hidden, for example any element with the ID ‘leaderboard-ad’. Page elements that match standard ad dimensions are also hidden. By hiding these page elements, adblock ensures that the space they would have taken up can be re-used by other parts of the page, such as the main page text. This has the bonus side-effect of also hiding any ads that slip by the first blocking technique.

Choose Your Bait Carefully

With these techniques in mind we insert bait elements into the page that adblock will attempt to block; including a javascript file, an image and an iframe. We then carefully observe what happens when a page loads. onLoad and onError events tell us if they’re successfully retrieved or if requests have been blocked. Their css style tells us if they are visible or have been hidden. We have run these tests billions of times, and have now refined them to the point that we can accurately detect when a user is blocking ads using adblock.

The Devil is in the Detail

As always, there’s more to this than meets the eye. Anyone who’s tried their hand at web development will be familiar with the frustration of cross-browser (in)compatibility and the challenge of staying current with a shifting landscape of browser and plugin technologies. Not to mention the challenge of  building a scalable server infrastructure that can handle vast quantities of analytics traffic in real-time.  We won’t bore you with complaints here though; hopefully you’ve now got enough information to understand what’s going on in the background when you sign up to use our free adblock measurement service.