Target (TGT -0.54%) played a strong e-commerce hand in the second quarter, showing an exceptionally robust 34% gain in digital sales from the year-ago period, which allowed both gross and operating margins to widen. 

There are indications the retailer's third quarter is going to be similarly muscular, and while it may be its e-commerce business that leads the way once more, investors might just want to keep an eye on its physical store performance, as that could be where the seeds of it beating Walmart (WMT 0.57%) are sown.

A girl pushing a shopping cart through a store

The back-to-school season could be the kickoff to torrid growth for Target in Q3. Image source: Target.

The king of retail

Simply because of its size, Walmart is a force to be reckoned with. Its own earnings showed even better growth than Target in e-commerce sales, which increased 37% year over year, but the digital operations have also served to drag down margins because of the investments it's making in infrastructure, online grocery sales, and start-up incubator Store No. 8. Target is finding a way to make its e-commerce sales profitable right now.

Still Walmart's stores are a big draw for customers. Analysts at Placer.ai, a foot traffic analytics platform, found that Walmart saw a 14.1% increase in store traffic from the first quarter to the second, significantly better than second-place Target, which had an 8.5% increase. Notably, discount chain Aldi, which has made a concerted expansion effort in the U.S., was the only top 10 retailer to experience a decline, suffering a 2.8% drop.

Walmart's vast footprint allows it to account for nearly half (47.3%) of total traffic of those 10 chains, far ahead of Target at 14.8%, but the third quarter could be where the differences between Target and Walmart really become clear.

The competitive difference

Analyzing store visit patterns over a period of years, Placer.ai found the two retailers walk pretty much lockstep across the year, with massive spikes naturally occurring during the Christmas holiday and strong increases around the back-to-school season.

That's played out again this year as the analytics firm sees Target just edging out the retail king at the start of the school year. Back-to-school traffic is soaring this year, up 27.5% from its baseline, compared to a 13% increase last year at this time, and a 10% rise the year before.

But there's a key difference that suggests Target is the stronger play, here, one that may make Target the best retail play: Its customers earn significantly more money than Walmart's.

Going to where its customers are

That's not necessarily a surprise, considering Walmart has always been the home of the cost-conscious low- to middle-income consumer, but Placer-ai found that Target sees 18% more of its customers earning $100,000 a year or more than Walmart does. That's key because of the expansion plans Target has.

As CEO Brian Cornell noted during Target's earnings conference call with analysts, the retailer has opened some 100 small-format, 15,000 square-foot stores in just the last two years, and it intends to open more at a pace of around 30 stores a year. It's found the smaller stores are twice as productive as its larger, 40,000 square-foot stores.

The smaller footprint allows it to build the stores in more urban areas where annual household incomes are also higher. Coupled with partnerships such as the one with Disney, which is opening store-in-store boutiques inside Target, Placer.ai believes these "make more sense as high-cost, branded products may find a strong connection with Target's audience."

More room to grow

There's still lots of time before Target reports its third-quarter earnings, but the retailer is off to a scorching start, which bodes well for the holiday season to come. Target's stock is up over 60% year to date, but it trades at just 16 times expected earnings, a substantial discount to growth stocks generally and to Walmart specifically, which goes for 23 times earnings and whose stock has gained 27% this year. Both go for a just a fraction of their sales, indicating a chance to gain more.

Considering the consistency Target is showing, its more affluent customers give the retailer a competitive edge over Walmart -- one it is exploiting with even more smart expansion strategies.