It took us only a few weeks to write our home-brew analytics package. Nothing super fancy yet now we have an internal dashboard that shows the entire company much of what we used analytics for anyway - and with some nice integration with some of our other systems too. I never quite grasp how the above isn't just a matter of intuition to anyone working in the tech sector. Google Analytics thrives on developers' lazine…
I've recently been faced with this problem, and a solution doesn't have to be too complex.
There are roughly two parts to an analytics solution: event logging and, well, the actual analytics.
Writing your own logger in javascript is super simple, you're just sending off json objects to be inserted into a elasticsearch cluster. Since you have to define that logging anyhow, the only extra work you need to do is the layer to do the actual ajaxrequests.
What's left is running and defining your queries in elasticsearch.
BAM! Analytics
I realize it's not fit to be used for every situation, but it can so some pretty complex things this way without the hugest amount of effort ...