Anti-adblock replacing div [duplicate]

0

I need a plugin for wordpress or script in which I get a message for the user who has adblock.

However, I want this message to appear instead of a div.

I've tried Plugins:

JGC AdBlocker Detector - This does not accept style (shows style as if it were plain text)

Ad Blocker Notify Lite - This works on the local server, but does not work on the online server.

    
asked by anonymous 25.04.2018 / 16:16

2 answers

3

You can use the BlockAdBlock (or FuckAdBlock

How do I answer: link

If you have jQuery (usually wordpress uses) you can do this:

<script src="blockAdBlock.js"></script>
<script>
(function() {
    function adBlockDetected() {
        $(function () {
            $('#div_especifica').text("adblock detectado");
        });
    }

    function adBlockNotDetected() {
        console.log("Sem adblock");
    }

    if(typeof blockAdBlock=== 'undefined') {
        alert("blockAdBlock não foi carregado");
    } else {
        blockAdBlock.onDetected(adBlockDetected);
        blockAdBlock.onNotDetected(adBlockNotDetected);
        blockAdBlock.on(true, adBlockDetected);
        blockAdBlock.on(false, adBlockNotDetected);
        blockAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected);
    }

    blockAdBlock.setOption('checkOnLoad', false);

    blockAdBlock.setOption({
        debug: true,
        checkOnLoad: false,
        resetOnEnd: false
    });
})();
</script>

Assuming the element is something like:

 <div id="div_especifica"></div>

Alternative

If you're using googleanalitycs you could use it like this:

<script>
function possivelAdblockDetectado () {
    $(function () {
        $('#div_especifica').text("adblock detectado");
    });
}
</script>

<script onerror="possivelAdblockDetectado()" async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
    style="display:inline-block;width:300px;height:250px"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="6440411535"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
    
25.04.2018 / 16:38
2

There are several ways to detect ad locks, however none is 100% guaranteed, I tested a% with_with% from a response from @Guilherme Birth: link

<script>
    function possivelAdblockDetectado () {       
        document.getElementById("id-div").innerHTML = "Conteúdo html que você quer mostrar no lugar";
}
</script>

<script onerror="possivelAdblockDetectado()" async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

This script tries to load Google ADS, if it is not possible, because of ad blocking (or any other reason), it will call a script function, and in it you can change content from possivelAdblockDetectado () % you want.

I hope I have helped!

    
25.04.2018 / 16:31