refactor google analytics code