I use a database to track all my ad clicks and log relevant data. I also use keyword reports to try and match cost to those clicks. However, I have not yet discovered a highly accurate way of doing this, for two reasons.

One, it is difficult to keep the database clean of spurious clicks from bots and even the likes of Google, so therefore there are generally too many clicks in the database. I can filter out bots using the user-agent, but even Google doesn't always have the word 'bot' for instance in all their clicks.

Second, the keyword cost is only provided by keyword. The only way I have got a reasonable match is by averaging the cost per click per day for the keyword then matching it in my db. It's all a bit woolly, but I cannot see a more accurate way of doing this. By the way, I don't want to use conversion tracking in Google for instance (a combination of paranoia and having a system that works with more than one ad provider).

So what do others do to filter out unwanted clicks, and secondly to match costs? I use php, but generally it is the methodology that is interesting. Of course, any good resources would be welcome :-)