How to prevent accidental clicks on your own adsense ads

Status
Not open for further replies.

dillinger

New member
Jun 27, 2006
127
4
0
I was just getting an arbitrage site ready and with all the testing I was doing I accidentally clicked an ad.It showed up in my account but as a $0 click.
I also noticed that with all the reloading of the page I artificially inflated my impression dramatically.
I went searching for a solution to this and found a piece of code in another forum and made a small improvement.I´m not a PHP coder so if any of you want to expand on this go ahead:

Code:
<?
$currentip = $_SERVER['REMOTE_ADDR']; 
$myip = "127.0.0.1"; // replace 127.0.0.1 with your own IP 
if($currentip == $myip) 
{
 
$google_id="ca-test"; // sets your publisher ID as a test account 
$channel=" "; //just in case they also track by channel id
} 
else
{ 
$google_id="pub-xxxxxx"; // Change to your real pub id
$channel="xxxxxxxxxx"; //Change to your real channel.Optional 
}
 
?>
(PHP syntax highlighting sucks on a grey background.)

What this code does is, when you access your own site from your own IP, it will replace the publisher id with a "ca-test" account, which apparently is a test account (from what I read in a bunch of places).I emailed google about this and have yet to receive confirmation.It will also replace the channel id with a blank one just in case.

What I did next in my adsense code was insert the variables:
Code:
<script type="text/javascript"><!--
google_ad_client = "<?=$google_id?>";
google_ad_width = 120;
(...)
google_ad_type = "text_image";
google_ad_channel ="<?=$channel?>";
(...)

All you gotta do is insert the PHP code above at the top of your site and save the page as a .php

Obviously if you are on a dynamic IP this will not work.Like I said, I´m not a php coder.

I´m also testing adlogger to prevent click attacks and for general adsense tracking.Gotta watch that hard earned money :D
 
  • Like
Reactions: Andrew


I posted about this a while back - I asked Google the same question, and they told me to insert the following line into the adblock when doing testing:

google_adtest='on';

I can confirm that neither clicks nor impressions are recorded when you set that variable.
 
Numbat said:
I posted about this a while back - I asked Google the same question, and they told me to insert the following line into the adblock when doing testing:

google_adtest='on';

I can confirm that neither clicks nor impressions are recorded when you set that variable.

Yes, I remember reading that too somewhere, but it was not confirmed.Did a google rep tell you this? I could find a way to add it to the code.
 
I simplified the code for you guys:

Code:
<script type="text/javascript"><!--

<?($_SERVER['REMOTE_ADDR']=="127.0.0.1")?"google_adtest='on'":"";?>

google_ad_client = "pub-1212121212121212";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "000000";
google_color_bg = "000000";
google_color_link = "000000";
google_color_text = "000000";
google_color_url = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

someone test it and let me know if there's a problem
the code uses a shorthand IF statement to check the current IP and if it's localhost then it will add google_adtest='on' to your adsense block
 
Isn't it against Google TOS to change the javascript code? If this works I'd love to try it.
 
Isn't it against Google TOS to change the javascript code? If this works I'd love to try it.


Wellz your actually going against Adsense TOS by messing with teh java script but its for a good cause so it should be okay!....but I would still check it with Google about though.
 
anyone using this modified javascript?? would also like to try it.
how is it working? any problems? got any email from Google yet?
 
I have been using it without any problems.
The code is modified server-side.There is no modification of the code to the end user.
 
I have been using it without any problems.
The code is modified server-side.There is no modification of the code to the end user.

sorry I'm a n00b....what did you mean by server-side? can I just change it in my adsense javascript...
 
by server side I mean that its changed by the php code on the server and then it is presented to the end user without any (apparent) modifications.
 
I posted about this a while back - I asked Google the same question, and they told me to insert the following line into the adblock when doing testing:

google_adtest='on';

I can confirm that neither clicks nor impressions are recorded when you set that variable.

Thanks a lot Numbat. This information has helped me a lot.
It works like breeze.
 
If I remember right, I think Shoemoney posted once on DP that he and his partners use a proxy so that they never even see the ads when they're working on their sites.
 
Status
Not open for further replies.