Analytics refactor