Collecting data when an ad blocker is enabled
There’s always a smarter way to get to the destination. Here’s the automated way of collecting specific information about website visitors, such as if an user uses AdBlocker when accessing one of our client’s websites, along with stats comparing the requests with and without the AdBlocker enabled.
Adblocker traffic (the traffic when an ad blocking is enabled) can be checked on Stats
section, in the Adblocker
tab. The
traffic is split into Mobile
and Desktop
. Also, a percentage of the entire
traffic is computed to give you a sense of the scale.
For a better understanding on how is adblocker traffic impacting your site, check out our article The Impact of Ad-blocking & Ways to Deal with it .
How is data being collected?
In order to collect data about the traffic with an ad blocker, we use a technique similar to the one used by the vast majority of WordPress plugins that do this kind of detection.
First, we inject into the page, a beacon used to count pageviews. That beacon is
a small script that will make a request to another javascript file, with
a random name (something like https://presslabs.com/vLkrhG9KjTqr.js?ts=53176
).
Now, if you’ve activated the ad blocker’s counter feature, that file will contain
the code needed to insert another beacon on the page. If not, it will just
display a small text like: // this beacon is used by PressLabs for metric computations on www.presslabs.com
.
That code is the magic sauce that will help to collect the data. It adds a very
small div
element, with position absolute, at -10000px
top and -1000px
left.
The div
element also has some special CSS classes and ids to bait any
ad blocker extension. In a loop — every 50ms — we run a test to see if the element
still exists. If, after 250ms, the element is still on the page, we call
/ads-beacon.js
, a dummy endpoint used by our log parser to count the traffic
without an ad blocker. After that (and also when the element was found missing), we
clean the ‘bait’.
How can I turn it off?
We try to be as non-intrusive as possible, and to avoid adding any overhead to the load time of the page.
The feature can be turned off by using the Adblocker detection
toggle, in the
Privacy
tab, from the Settings
-> Edge Servers
section.