Amazon.com Inc. handles nearly half of all online sales in the U.S., giving it a popular platform and a wealth of consumer data. Now it’s on track to become the next juggernaut of online advertising, and its rise threatens to upend Silicon Valley’s ad titans and change the business is done in Madison Avenue.