I keep coming across the question of how to track AdSense clicks. I found a great solution at http://www.tech-pro.net/track-adsense-clicks.html They provide a piece of javascript which can be inserted into each page. It allows for the creation of an extended entry in your web servers log, which contains the URL of the ad that was clicked. It calls an empty PHP script putting information about the click in the query to the script. I modified the javascript slightly so that the logging script could be located on a third party server. Instead of an empty PHP script, mine logs the date, time stamp, visitors IP address, and the query to a TABBED, plain text file. My solution is located at http://www.10-minute-rule.com/index.php?itemid=123 The Javascript is: <script type="text/javascript"><!-- function log() { if (window.status.indexOf('go to') == 0) { img = new Image(); img.src = 'http://www.MYDOMAIN.com/analysis.php?Ref=' + document.location + '&Url=' + window.status.substring(6) + '&Size=' + event.srcElement.width + 'x' + event.srcElement.height; } } var elements; elements = document.getElementsByTagName("iframe"); for (var i = 0; i < elements.length; i++) { if(elements[i].src.indexOf('googlesyndication.com') > -1) { elements[i].attachEvent("onfocus",log); } } //--></script> Code (markup): Change MYDOMAIN.com to your domain. And the PHP script is: <?php $query = strtolower( $_SERVER["QUERY_STRING"] ); LogEntry( "/PATHTO/MYHOME_DIRECTORY/ad-clicks", $query); ?> <?php ###################################################### # # Logging function LogEntry( $logfile, $message) { $date = date('M-d-Y'); $timestamp = time(); $message = $date . "\t" . $timestamp . "\t" . get_client_ip() . "\t" . $message . "\n"; $file = fopen( $logfile, "a"); fwrite( $file, $message ); fclose($file); } ############################## # retrieve the IP address of the user function get_client_ip() { if (isset ($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else $ipAddress = $_SERVER['REMOTE_ADDR']; return $ipAddress; } ?> Code (markup): Change "/PATHTO/MYHOME_DIRECTORY/ad-clicks" to a path and filename which works on your server and which works for you.
The javascript code needs to go before the closing body tag on your page. I use CSS to define the attributes of tags, not the content of the page. On my site pages are comprised of three sections -- header file, content file, and footer file. I placed the javascript in the footer file just before the closing </body> tag.
I simply use Adlogger script from Adlogger.org it's FREE and tracks ad page/ip of click blocks ips that do click fraud i love it so far