move analytics code to the right location