Related Articles

3 steps to report AdBlock users visits

3 steps to report AdBlock users visits

Wojtek Andrzejczak
Wojtek Andrzejczak
3 steps to report AdBlock users visits

Learn how to track in Google Analytics a user who uses AdBlock.

AdBlock usage statistics

Depends on the country and website, users who use any kind of AdBlock software is between 10% and 48%.

How could we measure AdBlock users?

And this is a bit of a challenge. Most of the AdBlock software blocks analytics software like Google Analytics or Adobe Analytics. But also any tag managers like Google Tag Manager or Adobe Tag Manager.

So if we would like to track those users, we’d have to do this on the server-side, not on the client-side.

Google Analytics Measurement Protocol

Measurement Protocol allows sending HTTP requests directly to the Google Analytics servers without default JavaScript snippet. The downside is that we have to code everything by our selves.

Prepare a script to detect AdBlock

First of all, we need to create on all pages script which will detect if any AdBlock is available on the page. Script tries to create an element with “ad” related IDs and attributes so that any AdBlock software would block/hide it on the page. If the 1×1 element created by us does not have any height, then it is blocked.

      function getCookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for (var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
            c = c.substring(1);
          if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        return "";

    function AdBlockEnabled() {
      var ad = document.createElement('ins'); = 'AdBanner';
      ad.className = 'ad adsense google ad-slot'; = 'block'; = 'absolute'; = '-1px'; = '1px'; = '1px';

      var isAdBlockEnabled = !ad.clientHeight;
      return isAdBlockEnabled;

    function adBlockCallback() {
      var params = [];
      params.push({key: 'dh', value: window.location.href});
      params.push({key: 'dp', value: window.location.pathname});
      params.push({key: 'cid', value: getCookie('adb_uuid') || new Date().getTime()});
      params.push({key: 'tid', value: 'UA-149687655-1'});
      params.push({key: 'ul', value: navigator.language});
      var query_params = params.reduce(function(acc, item) { 
        var chunk = item.key + '=' + encodeURIComponent(item.value);

        return acc ? acc + '&' + chunk : chunk; 
      },  null);

      var http = new XMLHttpRequest();
      const url = '/hit_adbu.php?' + query_params;'GET', url);

    window.onload = function() {
      if (AdBlockEnabled()) {

Create a backend piggyback script.

When the script on the page detects AdBlock, then an AJAX request is sent to the website script (in our case, PHP script) to inform Google Analytics about user visits.

Script bellow sets an adb_uuid Cookie, to identify the same user over a period of time, to avoid multiply unmatched Page View hits.


header("Expires: Tue, 03 Jul 2001 06:00:00 GMT", true); // *
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT", true);
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0", true);
header("Pragma: no-cache", true);

function responseWithCookie($name, $value, $ttl=31536000) {

    $domain = $_SERVER['SERVER_NAME'];
    $expires = time() + $ttl;

    if ($_SERVER['REQUEST_SCHEME'] === 'https') {
        $options = [];
        $options['expires'] = $expires;
        $options['path'] = '/';
        $options['domain'] = $domain;
        $options['secure'] = false;
        $options['httponly'] = false;

        if ((float)phpversion() >= 7.4) {
            $options['SameSite'] = 'none';
            $options['secure'] = true;

        setcookie($name, $value, $options);
    } else {
        setcookie($name, $value, $expires, "/", $domain);

    $_COOKIE[$name] = $value;

function getKey($items, $key) {
  if (!$items) return null;
  return array_key_exists($key, $items) ? $items[$key] : null;

$dh = getKey($_GET, 'dh'); //****
$dp = getKey($_GET, 'dp'); //****
$cid = getKey($_GET, 'cid'); // User Unique ID
$tid = getKey($_GET, 'tid'); // UA-****
$ul = getKey($_GET, 'ul'); // en-us

parse_str(parse_url($dh, PHP_URL_QUERY), $query_params);

$utm_campaign = getKey($query_params, 'utm_campaign');
$utm_source = getKey($query_params, 'utm_source');
$utm_medium = getKey($query_params, 'utm_medium');

if (!$dh || !$dp || !$tid) {
foreach ($_COOKIE as $key => $value) {
    $strCookie .= $key . '=' . $value . '; ';

$fields = array (
    'v' => 1,
    'tid' => $tid,
    'cid' => $cid,
    'uip' => $_SERVER['REMOTE_ADDR'],
    'dh' => $dh,
    'dp' => $dp,
    'ul' => $ul,
    't' => 'pageview',
    'cd6' => 'true'

if ($utm_campaign) {
    $fields['cn'] = $utm_campaign;

if ($utm_source) {
    $fields['cs'] = $utm_source;

if ($utm_medium) {
    $fields['cm'] = $utm_medium;

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, utf8_encode(http_build_query($fields)));
curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, $strCookie);

$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;

responseWithCookie('adb_uuid', $cid);

header('Content-type: image/gif');
echo $content;

Create a GA Custom Dimension

To let us distinguish users with and without AdBlock, we need to create a Custom Dimension in Google Analytics.

AdBlock user visit / Google Analytics / Custom Dimension
AdBlock user visit / Google Analytics / Custom Dimension

User visit with AdBlock

To check how our solution works, with enabled AdBlock, we can find in Chrome DevTools a new request called “hit_abdu.php”, which is called by our script from the 1st step.

Google Chrome / DevTools / AdBlock user visit
Google Chrome / DevTools / AdBlock user visit

User visit without AdBlock

Without AdBlock, there would be no “hit_abdu.php” request.

Google Chrome / DevTools / Non AdBlock user visit
Google Chrome / DevTools / Non AdBlock user visit


As you can see on the image bellow, reported users from the last 7 days is about 11%. We can estimate the percentage share of the AdBlock users which impacted our campaigns.

Google Analytics / AdBlock users
Google Analytics / AdBlock users


  • Contact Me
    Contact me if you need advice or if you need help. Would you please choose the most suitable contact channel for you?
  • My Services
    If you need a technical specialist to technical support to fix your problems, you are in the right place.
  • Who I am
    Hello, my name is Wojtek, I’m an experienced Software Engineer, with many many years of experience in the advertising industry.

Subscribe to receive updates about new articles.

[newsletter_form button_color=”#E74C3C”]
Show Comments (2)


  • shoulderposture

    Hello I am so delighted I found your webpage, I really found you by accident,
    while I was searching on Aol for something
    else, Nonetheless I am here now and would just like to say many thanks for a remarkable
    post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read through it all at the minute but I have bookmarked it and also added your RSS feeds,
    so when I have time I will be back to read a lot more, Please
    do keep up the fantastic jo.

    • Article Author
    • Reply
  • Anonymous

    Hum i have to change the tid params.push({key: ‘tid’, value: ‘UA-149687655-1’}); with my analytics UA property right?

    • Article Author
    • Reply

Related Articles

Dynamic Creatives for Programmatic DOOH

Dynamic Creatives for Programmatic DOOH

Since Programmatic Digital-Out-Of-Home (DOOH) is getting more popular, it also brings questions about how we could take an advance it. One of those advantages can be Dynamic...

Posted on by Wojtek Andrzejczak
5 facts about UTM tracking parameters • Google Analytics
Google Analytics

5 facts about UTM tracking parameters • Google Analytics

Google Analytics UTM tracking parameters, what they are, and how to use them in digital advertising. What Google Analytics UTM’s is? UTM allows us to tag URLs with...

Posted on by Wojtek Andrzejczak