Are Ad Blockers stealing your revenue? There are many browsers out there that come with AD Blockers installed by default. I guess that is good if you are a consumer and want to get free information all the time without compensating the content creator for their hard work. However, if you are a content creator, this does not seem fair does it?
Ad Sense by Google
Many content creators like me use AdSense by Google. This is a great avenue to make some money off of the content that you publish. However, many Ad Blockers out there are cutting into your income. So what can you do to combat this?
Please Allow Ads
So you can politely ask people to let ads display on your site. This is probably the best approach. If they keep their ad blocker activated on your site they will get a message like this on every page.
How to Implement Ad Blocker Detection
Here is a script that you can use. Put it towards the footer on your pages. It will give a visitor a notice like above on every page they visit as long as their ad blocker is enabled.
Using Google AdSense can actually simplify ad blocker detection, as many ad blockers specifically target AdSense scripts. Here's an approach tailored for detecting blocked AdSense ads without triggering false positives:
AdSense-Based Ad Block Detection
We’ll load a small, invisible AdSense ad unit and check if it’s rendered. If it doesn’t render, we can assume an ad blocker is active. Here’s the code:
- Load a Small AdSense Ad: We’ll add an invisible AdSense ad container.
- Check for Ad Blocker: If the ad fails to load, an ad blocker is likely active.
Implementation Step 1
Load small AdSense ad.
<!-- Step 1: Ad container with a small AdSense ad unit --> <div id="adsense-test" style="width: 1px; height: 1px; overflow: hidden;"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:inline-block;width:1px;height:1px" data-ad-client="ca-pub-your-client-id"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div>
Implementation Step 2
Check for Ad Blocker
<!-- Step 2: Detection script --> <script> function detectAdBlock() { const adContainer = document.getElementById('adsense-test'); setTimeout(() => { // Check if the AdSense ad was blocked or not displayed if (adContainer && adContainer.offsetHeight === 0) { alert("Please disable your ad blocker to support our content!"); // Or replace the alert with a banner or modal message here } }, 1000); // Wait for a second to give the ad time to load } window.onload = detectAdBlock; </script>
How This Works
- Invisible AdSense Ad: The
<ins>
element with a small inline-block style (1x1 pixel) is a minimal ad unit that should load quickly if AdSense is allowed by the browser. - Offset Height Check: If the ad container’s height remains zero after a second, it likely means the ad was blocked.
- Custom Alert or Message: Replace the alert with a modal or banner for a smoother user experience.
Testing the Detection
- With Ad Blocker Enabled: If the ad blocker blocks the AdSense ad, the offset height will be zero, triggering the alert or custom message.
- Without Ad Blocker: When there’s no ad blocker, the ad should load, and no message will be shown.
This approach leverages AdSense itself and should help reduce false positives, as it directly checks for the presence of AdSense ads.