Amazon’s profits tripled from a year ago, while Facebook and Google rode a major rebound in ad spending.