Moved analytics code to own file.