Move analytics code into the analytics handler

Addresses issue #18.