Menu:

Recent Entries

Categories

Archives

Links

Blogs
- Dflying's Night
- David's Untitled Life
- Dflying's Blog in Chinese

This blog is hosted by DreamHost!

Syndicate

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Google Adsence Statistics Tool

Dflying | 03 March, 2006 22:26

Google Adsence page do not provide detailed statistics, e.g. when your ads are clicked, where is the clicker's IP, what ad does he/she clicked or which page the clicked ad is placed.

We could simply use some client and server site script to record these data for your infomation. I'd like to choose Javascript and PHP to make it.


Firstly, try to get the click behavior using Javascript. After checking the DHTML code Adsence generated, I writes following code:

function log() { 	
  if (window.status.indexOf('go to') == 0) { 
    bug = new Image(); 
    bug.src = 'path/to/your/log.php?
src=' + document.location
+ '&url=' + window.status.substring(6); 		
  } 
} 
 
var elements;
elements = document.getElementsByTagName("iframe"); 
 
for (var i = 0; i < elements.length; i++) { 
  if(elements[i].src.indexOf('googlesyndication.com')
     > -1) { 
    elements[i].onfocus = log; 
  } 
}

Here get the text on browser's status bar and pass to a server side script, log.php. Following is the code in log.php

$entry = $_SERVER["REMOTE_ADDR"]."t"
.$_GET['src']."t".$_GET['url']."t"
.date("F j, Y, g:i a")."rn";
 
// should be fopen/fwrite/fclose, seems 
// my hoster does not allow to input file
// functions in form post data, donot know why.
$dataFile = f_open('data/data.txt', 'a');
f_write($dataFile, $entry);
f_close($dataFile);

The php code logs the clicker's IP address, visiting page, ad url and click datetime, then appends to a text file.

OK, save the javascript file to click.js and add to the end of your web pages which contain ads.

<script type="text/javascript" src="path/to/your/click.js">
</script>

Then upload the php page to you server and try to click your ads. If everything's ok, you may check the data.txt to find your logs. ;)

This is just the simplest implementation and everything can be done much better. E.g. IP location lookup, good UI or save data to database... Good luck!

Posted in General. Comment: (4). Trackbacks:(157). Permalink
«Next post | Previous post»

Referers

Comments

  1. 1. Zhu Xinquan  |  03/05,2006 at 19:29

    How could you style your javascript code in your entry?

  2. 2. Dflying  |  03/05,2006 at 22:50

    It is a highlighter called GeSHi. Please refer to http://dflying.dflying.net/1/archive/16_new_plug-in_plogeshi.html

  3. 3. Zhu Xinquan  |  03/06,2006 at 01:12

    The highlighter requires php support.
    But I am searching a way to convert it to HTML code.
    BTY, Your blog's comment system make me feel unconvenient. I think it will be better if I can remember my personal info when I post a comment.

  4. 4. Dflying  |  03/06,2006 at 02:19

    There's not only html code but also lots of stying issuse so it is not easy to convert the code into static html format, I think.
    I will try to make a cookie based 'Remeber Me' plugin for LifeType.

Leave a Reply

Auth Image