Processing statistics: upon page request or by pixel-tracking
===

I'm currently in the process of developing a statistics module for my pages. I'm currently considering the following two techniques to enable page-specific statistics:

 1. **Querying the database directly upon request**. This increases the time it takes to generate the page by about 100-200ms, which **increases** the **overall time** it takes to generate a page = bad.

 2. Using a technique like **[tracking pixel][2]**. Inserting a 1x1 image at the bottom of my content, ensuring it gets loaded after all the content has been loaded. This **doesn't** directly **affect page generation times. 
 `<img src="tracking.php?pageID=391" width=1 height=1 />`

I'm not stupid – I do realize that somewhere it will take the server 200ms to handle the information (gather, structure and insert), however, this shouldn't affect the user. 

One adventage I can see by using method one is that the statistics are updated BEFORE content is served, as opposed to method two – meaning that half-a-second visits counts too. Sometimes good, sometimes bad. 

What's the **prefered way**, **preformance** and **smoothness** wise to **process statistics** data? I'm open to other techniques aswell. 

  [2]: http://en.wikipedia.org/wiki/Web_bug
