To create your own data collection scripts would require lots of things: Javascript and/or jQuery, PHP, a database, and quite a bit of time. You could use JavaScript or PHP to get information about the visitor on each page they visit.
Unless you are ready for a pretty heavy time investment, I'd suggest going with an open source alternative platform. I suspect this is what you're after, but I might be wrong.
The following have extensive dashboards that provide pretty good information. They are both PHP programs that live on your server and save information in a database on your server. While not as simple as using Google Analytics or similar, you have control over the data and a lot more functionality.
Open Web Analytics:
http://www.openwebanalytics.com/
Demos: http://demo.openwebanalytics.com/
See install instructions here: http://wiki.openwebanalytics.com/index.php?title=Installation.
Piwik:
Demo: http://demo.piwik.org/
Install and configure: http://piwik.org/user-guide/ Install video: http://piwik.org/blog/2012/10/how-to-install-piwik-analytics-video/
Update: Piwik is now called Matomo - https://matomo.org/