0

So i'm trying to get mouse down events to trigger when people click my ads in my div tag Why? because I have a friend whose adsense account was banned because of invalid clicks. What i'm wanting to do is have it record the IP and once an ad is clicked, all the ads will disappear for about 5 days before appearing again, meaning that they cant continuously click the ads, which results in the adsence account banned.

What I have done to test is this

<script>
function mouseDown() {
    alert("Yes");
}
</script>

<p id="myP" onmousedown="mouseDown()">
Does this work?
</p>

This works for when someone clicks the text, and shows the message "Yes". But when I put a ad inside

<div class="myAds" onmousedown="mouseDown()">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-2948xxxxxxxxx2"
     data-ad-slot="6735xxxx36"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>

It doesn't work, all it does is go strait to the ad without any alert

can someone help with this issue, or any other work around?

esqew
  • 42,425
  • 27
  • 92
  • 132
jLynx
  • 1,111
  • 3
  • 20
  • 36
  • The reason the mousedown event will not work is because the ad tag creates an iframe causing the same issue described [here](http://stackoverflow.com/questions/3690812/capture-click-on-div-surrounding-an-iframe). This will explain in more detail why you are having issues. The solution provided in that link might not work in your scenario but it's a start. – Edgar Sanchez Nov 24 '14 at 05:24

1 Answers1

0

I have made a GitHub project for this over here https://github.com/DarkN3ss61/Adsense-Blocker Basically what I needed to do is this

var isOverGoogleAd = false;

var ad = /adsbygoogle/;

$(document).ready(function()
{   
    $('ins').live('mouseover', function () {
        if(ad.test($(this).attr('class'))){
            isOverGoogleAd = true;
        }
    });
    $('ins').live('mouseout', function () {
        if(ad.test($(this).attr('class'))){
            isOverGoogleAd = false;
        }
    });
});

$(window).blur(function(e){
    if(isOverGoogleAd){
        $.ajax({
            type: "post",
            url: "AdsenseBlocker/recorder.php",
            data: {
                adUrl: window.location.href
                }
        });
    }
});

So you have a mouseover and mouse out function which sets the Boolean to either true or false depending on weather the mouse is inside of the ad, and once they click on the ad, the outer webpage gets blured becasue the ad in the iFrame gets focused, so if isOverGoogleAd is true and the outer ad page gets blured, then we assume that an ad was clicked

jLynx
  • 1,111
  • 3
  • 20
  • 36