How to Track Ad Blockers in Google AnalyticsAd Blockers are becoming ever increasingly popular among web visitors. This guide will show you how to track ad blockers in Google Analytics

As the use of Ad Blockers continues to surge, it's crucial for web publishers to understand their impact. While these tools are primarily installed to curb intrusive ads, they often indiscriminately block subtle ones, significantly affecting web publishers. This guide is designed to help you navigate this challenge by demonstrating how to track ad blockers that are blocking Adsense traffic in Google Analytics.
Ad blocking is a pervasive issue that affects not just ad publishers, but also content writers like me. We rely on advertising revenue to offset the costs of server hosting and content creation. However, ad blockers have significantly impacted this revenue, to the point where some of us struggle to maintain our services or keep our content updated. In my case, my Adsense income has dropped by a third over the past five years, and while I can't attribute it all to ad blockers, they certainly haven't helped.
Blocking ads and trackers in a browser enhances user privacy and security by preventing websites from collecting personal data and tracking online behaviour. It also improves the browsing experience by reducing distractions, speeding up page load times, and conserving bandwidth.
Fortunately, there's a straightforward method to track ad blockers and detect if Adsense codes have been blocked. This method uses a few JavaScript variables that Adsense utilizes. If Adsense is blocked, these variables remain unset. By testing for this condition and sending an event to Analytics for logging, we can gather data on the percentage of ad-blocked visitors. Armed with this information, you can take steps to mitigate the problem, thereby safeguarding your revenue.
It is important to note that if the Ad Blocker is also blocking Analytics, this method won't be effective. However, you have the power to adapt it to log elsewhere, ensuring that you're not left without a solution. The code can be modified to work on other ad publishing platforms, giving you the flexibility to address the issue across different channels.
You will need Google Analytics and a Google Adsense account for these examples.
Ad Blocker Detection Code
The simple code can be copied and pasted into your website without changes. This is usually in the page's footer after your Analytics tracking script.
if(typeof adsbygoogle !== "undefined")
{
if(typeof ga !== "undefined")
{
if(typeof adsbygoogle.loaded === "undefined")
{
ga('send', 'event', { eventCategory: 'Income', eventAction: 'Adsense', eventLabel: 'Adsense Blocked', eventValue: 1});
}
else
{
ga('send', 'event', { eventCategory: 'Income', eventAction: 'Adsense', eventLabel: 'Adsense Not Blocked', eventValue: 1});
}
}
}
With this script logging an event to Analytics with the title "Ads blocked" or "Ads not blocked," you can then see in Google Analytics reports the proportion of blocked page views and how many are not blocked.
This script will wait until the page has finished loading and then check for the adsbygoogle variable. It then checks the existence of the AdSense and analytics codes. It fires off an event depending on whether the ads by Google are loaded.
Track Ad Blockers in Google Analytics
Now that the track ad blockers script has been added to the page, we need to wait a few days for the tracking data to start coming through. Once it does, you can view the events from the Behaviour > Events screen in Analytics reporting.
