Add Google Analytics, cleanup and use best practices

This PR adds support for google analytics as discussed by email.

It also cleans up some things and adopts best practices.

@ni