Header Ads

  • Breaking News

    Ad Blocker Detector for Google Adsense with JavaScript

    Advertisements are very important for any post published in internet. This is what decides the person’s revenue. But, recently adblocker system is killing revenue of the publisher because of which it also effects the creativity of that person. Today, I am providing a simple new solution for those depressed and effected persons of adblocking system. Here is a simple javascript to be included along with your website code to either hide the content of your website or show a pop-up or alert message to remove the viewers adblock plugin. Any blogger or any website management can use this code to improve your revenue of your website. This code is mainly designed for Google Adsense.

    Google Adsense
    You have to include onerror event to the script tag, this will trigger adBlockFunction()Javascript function.
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"onerror="adBlockFunction();"></script>
    <ins class="adsbygoogle"
    style="display:inline-block;width:300px;height:600px"
    data-ad-client="ca-pub-XXXXXXXXXXXXX"
    data-ad-slot="XXXXXXX"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>


    Ad Blocker Function
    This contains very simple JavaScript code, this will replace article content part with ad blocker message. If you are Google Blogger user don't change the class name post-body-n. This function helps you to track ad blocker usesr count with Google Analytics.
    <script>
    function adBlockFunction()
    {
    // Google Analytics Tracking 
    setTimeout(function() {
    ga('send', 'event', 'Blocker', 'click','Blocker');
    },2000);
    // Google Analytics End

    // Website Users
    document.getElementById('contentDivName').innerHTML = 'Please disable your ad blocker for yourwebitename.com';

    // Google Blogger Users
    document.getElementsByClassName('post-body-n')[0].innerHTML = 'Please disable your ad blocker for yourwebitename.com';
    }
    </script>

    Google Analytics Result
    For more information read this article Google Analytics Custom Dashboards for Websites


    Sample Website HTML Code
    //HTML Code
    <div id="container">

    <div id="contentDivName">
    Article Content Part // This will replace with ad blocker message
    </div>

    <div id="sidebar">
    Google Adsense Code
    </div>

    </div>

    Ad Blocker Function for Alert Bar like ramji parmar
    <script>
    function adBlockFunction()
    {
    // Google Analytics Tracking 
    setTimeout(function() {
    ga('send', 'event', 'Blocker', 'click','Blocker');
    },2000);
    // Google Analytics End

    document.getElementById('ab-message').style.display = 'block';
    }
    </script>

    HTML Code
    Include the ad-message div tag after the tag <body>
    <style>
    #ad-message{
    text-align: center;
    background-color: #E23C3C; color: #ffffff;
    font-weight: bold; font-family: Arial;
    border-bottom: solid 1px #333333;
    }
    </style>

    //HTML Code
    <body>
    <div id='ad-message' style='display: none;'>
    Please disable your ad blocker for yourwebitename.com
    </div>
    .....
    .....

    No comments

    Post Top Ad

    Post Bottom Ad