Trending Posts

mint screenshot

Make Money Online: Documenting 10 Years of Failure

By John Ward / March 20, 2015 / 65 Comments
This is the history of my experience trying to make money online over the past 10 years or so. This is by far the longest post I've ever personally written and it's more of an autobiography than a blog post....
pancakeswap prediction bot

I Made an Automated Pancakeswap Prediction Bot

By John Ward / October 14, 2022 / 0 Comments
A few weeks ago I got the idea to try to automatically bid on Pancakeswap's Prediction game. So I decided to try to build a Pancakeswap Prediction bot to take on the task. I did this just to learn about...
IBM Watson Avatar Logo

IBM Watson Explorer

By John Ward / April 6, 2015 / 1 Comment
I'm going to talk a little bit about IBM Watson Explorer (WEX). A few people have contacted me about what I do at my day job as a Watson Explorer Consultant. Since this is my personal site I don't usually...
what is ibm watson

What is IBM Watson

By John Ward / July 24, 2020 / 0 Comments
There is a lot of confusion about what exactly IBM Watson is? I'm going to try to clear that up a little bit in this blog post. I'll go into the history of IBM Watson and what IBM is doing...
2022

My 2022 Recap and 2023 Plans

By John Ward / January 13, 2023 / 0 Comments
I haven't been posting to my blog that often, but I wanted to recap 2022 and lay out some of my plans for 2023. Overall, 2022 was a pretty good year for me, and I made some progress on business...
watson explorer vs elastics earch

Watson Explorer vs Elasticsearch for Enterprise Search

By John Ward / May 12, 2020 / 0 Comments
Are you interested in IBM Watson Explorer vs Elasticsearch? Recently, I had to do some comparisons between IBM Watson Explorer and Elasticsearch for a project. I spent some time going through the features of both platforms and found some interesting...

One AdSense Change Dramatically Increased My Earnings…

By John Ward / March 9, 2015 / 12 Comments
... and I have no idea what it is. I used to blog actively on my tutorial site, TeamTutorials. In it's prime the site would see over 100k page views per month. Even in the prime the site barely met...

Are Products the Road to Prosperity?

By John Ward / May 13, 2015 / 1 Comment
A few weeks ago a wrote a somewhat popular post about my past experiences trying to make money online. I went through the ups and downs of working as an affiliate promoting other people's products. At the conclusion of the...

Regular Expression Converter for Watson Explorer Engine

By John Ward / August 23, 2019 / 0 Comments
Sometimes it's useful to extract data from a Watson Explorer content node using regular expressions. In this post, I'll show you how to extract data using a regular expression and create a new content node for that specific data. To...
ibm watson discovery fundamentals

IBM Watson Discovery Fundamentals Training

By John Ward / October 28, 2020 / 0 Comments
I'm excited to announce that I've released my first course on Udemy titled IBM Watson Discovery Fundamentals. This course is designed to give business and technical users a good high-level overview of the IBM Watson Discovery service. What is IBM...

Tracking Ad Blockers Using Google Analytics

If you’ve read any of my older posts you probably know that I’ve been involved in internet advertising, in some form, for a long time now. Lately I’ve been seeing more and more posts about how ad blocking is growing at a tremendous rate. I still have some sites that make money from display advertising so I was curious just how many of my users are actually using ad blocking tools. I decided to see if there was a way I could track the users who do use tools like AdBlock vs the users who do not.

First, I came across a script called Block Ad Block. The intention of the script appears to be to detect ad blockers and allow the site owner to act on that knowledge. As a site owner I could detect that a user is using an ad blocker and decide not to display the content to that user. I could also replace the ad block with something like a donations link, an image that tells the user they are a leech, etc. This is all done client side via JavaScript so ultimately the user could still display the content if they disabled JS. I don’t have an interest in punishing people but I saw a way I could use this script to capture the data I wanted.

I noticed that the script allows custom code to be executed when adblock is detected or not detected. Then I remembered that Google Analytics allows you to set custom variables. Combining these two functions we should be able to track which users are using ad blockers in Google Analytics.

First you want to download blockadblock.js. Rename it to something else, I called mine GA.js and include it in your site’s header.

Then create the following Javascript file and include it in the header.

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'YOUR_SITES_GA_ID']); // set GA id here

function adBlockNotDetected() {
    _gaq.push(['_setCustomVar', 1, 'AdBlock', 'No', 1]);
    _gaq.push(['_trackPageview']);
    // could execute custom JS if not detected
}
function adBlockDetected() {
    _gaq.push(['_setCustomVar', 1, 'AdBlock', 'Yes', 1]);
    _gaq.push(['_trackPageview']);
    // could execute custom JS if detected
}

if(typeof blockAdBlock === 'undefined') {
    adBlockDetected();
} else {
    blockAdBlock.onDetected(adBlockDetected);
    blockAdBlock.onNotDetected(adBlockNotDetected);
}

blockAdBlock.setOption('checkOnLoad', true);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

This script include google analytics so you don’t want to include it anywhere else. Also there is a section where you can trigger your own JavaScript to run if adblock is detected. For example you could beg for donations if the user is using adblock.

After this runs for awhile it will start collection custom variable data. You can check the data in the Google Analytics dashboard by going to Your Site -> Audience -> Custom -> Custom Variables. You will see one that says “adblock”. If you click the link it will then take you to a report that shows if a user has adblock enabled or disabled. Yes means adblock was detected:

Google Analytics Detect Ad Blockers

When I look at my data I generally see that somewhere around 20% of my users are using ad blockers. Seeing as the script is written in client side JavaScript and so is Google Analytics, you won’t be able to capture any data if the user has JavaScript disabled. That still seems to be even a more extreme minority than the number of AdBlock users. If I get bored or there is enough interest I may turn this into a WordPress plugin.

 

Published by

John Ward

I've been in working in the tech space since about 2004. I've spent time working with Artificial Intelligence, Machine Learning, Natural Language Processing, and Advertising technology.