move code into js file and use analytics events to track links