Walmart (wmt, -2.38%) has poured billions into its e-commerce and tech to integrate its digital business with its stores, and the strategy is paying off handsomely.

The retailer said comparable sales at its 4,000 U.S. stores, a $300 billion a year business, rose 1.8% on the year in the three months to June, well above Wall Street expectations for 1.3% according to Consensus Metrix. That gave Walmart U.S. its 12th straight quarter of growth.

More crucially for the world’s largest retailer, shopper visits also increased, rising 1.3% and showing that Walmart’s massive investments in features like grocery curbside pickup, in-store order retrieval, its own mobile payment app and the expansion of its online assortment are spurring shoppers to come into stores.

The company has made clear that it sees the full integration of its U.S. stores and e-commerce as its best weapon to compete with (amzn, -0.45%). Revenue from online sales rose an impressive 60% year-on-year.

But investments, along with more aggressive pricing generally, cost money. The company disappointed Wall Street with a…