What is the best way to detect ad blocker

Ask a question+

I have a website that displays Google ads. I was wondering how it is possible to detect the number of visits with ad blockers and display a message.

Vazgen Manukyan 610
add comment

2 Answers


There is a fairly simple solution to this if you are open to using jquery. Also, I used PHP here, but other languages are options too. Then store in a database table.

This function detects the height of the AD. If it’s 0, it’s clearly blocked. This function works fairly well, can be tested here:

function DetectAd() {
    if ($('.myAdIDForExample').height() == 0) {
        var x="<?php updateAdBlockAmount(); ?>";     //This calls my PHP function, seen below
     var x="<?php updateAdNotBlockAmount(); ?>";     //This calls my PHP function, seen below

//Called on page load


//PHP function

    function updateAdBlockAmount{
    Here you simply add another one to the blocked value in your table
function updateAdNotBlockAmount{
Here you simply add another one to the NotBlocked value in your table

SQL table:
Blocked, Notblocked

Lainrawr 305
add comment

I have come up with an idea of how to estimate. It is not the best solution, but I compare the page views in google analytics and google ad sense. So the ratio is what I am looking for. The website is w3docs.com, and it shows that 51% of users (developers) use ad blockers.

Arthur Dilanyan 530
add comment

Your Answer