refactor out analytics