Here are two recommendations:
Open Web Analytics - an open source framework that will let you setup your own PHP server and use an out of the box JS client for reporting
How To Create Your Own Stats Program (JavaScript, AJAX, PHP) - a good sample that will let you understand how to build a simple solution from scratch.