Very similar code exists in `analytics`. Why is it duplicated here?