Instead of rolling your own look at Piwik. It works very well and is basically a GA clone. I actually like it <i>better</i> than GA in some ways. It&#x27;s easy to set up and you can run it on your own site so you&#x27;re not contributing to a global tracking fabric.