Fix analytics code and add tracking event