0

Adblocker detection when using Google Doubleclick for DFP and tracking to Google Analytics

A lot of websites operate on ad revenue. But also a lot of people have installed adblockers so the website owner will get no money. It is very interessting how many people use adblockers so we are going to track this with Google Analytics event tracking.

Doubleclick for DFP has this one global var gadsize which is undefined when an adblocker is installed and activated. So after the page has finished loading, we check if gadsize is defined. If yes, no adblocker is installed.

Javascript

window.onload = function() {
    // little delay
    setTimeout(function() {
        if (typeof _gaq !== 'undefined')
        {
            if (typeof gadsize !== 'undefined')
            {
                _gaq.push(['_trackEvent', 'Adblock', 'No', undefined, undefined, true]);
            }
            else
            {
                _gaq.push(['_trackEvent', 'Adblock', 'Yes', undefined, undefined, true]);
            }
        }
    }, 1000); // run 1 seconds after page has loaded
};

Michi

Passion for sports with boards, climbing, mountain biking, traveling, photography, videography and software engineering.
/n/n
Heilbronn // Germany

Leave a Reply

Your email address will not be published. Required fields are marked *