Moved analytics code into scripts.js and added some events