Few days ago I wrote a little extension called Inchoo_Piwik. Piwik is a free downloadable open source web analytics software. Piwik provides you with detailed reports on your website visitors; the search engines and keywords they used, the language they speak, your popular pages, and much more (official definition from http://piwik.org/). Inchoo_Piwik simply connects your Magento to Piwik installation whose parameters you assign trough extension configuration screen.
Please keep in mind that this is the basic implementation which enables you to track your site in Piwik. All of the possible advanced stuff might need additional modifications of code.
Extension source code files can be found here at GitHub. It follows the structure of Magento extensions so you should be able to download it and copy paste it into the root of your Magento.
Hope it helps. Cheers.