Retailers are building a digital flywheel that spans personalization, loyalty, and now an advertising business fueled by first-party data.