With just a few weeks left in the year, Target (TGT 0.70%) stock is on track to post dramatic annual gains for its shareholders. The stock price is up by more than 30% so far in 2018, putting the retailer's returns well ahead of both the broader market and its main rival, Walmart (WMT -0.32%). It even edged past the share price gains of Costco (COST -0.11%), despite the warehouse giant's stronger earnings profile.

You don't typically see an outperformance like that without a fundamental improvement in the operating trends of the company in question. And that's exactly what Target provided in 2018.

Heading in the right direction

Target started delivering its good news early, telling investors in January that its 2017 holiday season results had come in much better than expected. Rather than a flat year-over-year result for November and December, executives said, the chain had achieved a 3% sales increase in the critical shopping period.

Two women pick out clothes.

Image source: Getty Images.

In that report, and in Target's subsequent three earnings releases, the standout metric has been customer traffic. The figure shot up by 3.2% in the full fourth quarter, the retailer revealed in March, then rose by 3.7% year-over-year in the fiscal first quarter.

Target's fiscal second-quarter report contained the most encouraging news, as shopper traffic gains accelerated to 6.4% -- its best result in over a decade on that score. Other major retailers have been posting accelerating traffic growth rates, too, but not to such a high level. Walmart's customer traffic gain was 2.2% in its second quarter, and Costco's comparable figure was closer to 5%.

To be sure, Target has had some misses during the year as well. The retailer's profits came under significant pressure due to a more aggressive pricing strategy, coupled with its expensive push to expand its e-commerce sales. As a result, gross profit margin fell during the last two quarters and operating income declined from $2.25 billion (6.9% of sales) to $2.17 billion, (6.4% of sales). This trend contrasts sharply with Costco's rising profits, but it's significantly less painful than the profit pinch being felt by Walmart.

COST Operating Income (TTM) Chart

COST Operating Income (TTM) data by YCharts

Looking ahead

In fact, this period of declining profitability was something that CEO Brian Cornell and his team had warned investors to expect. They predicted back in March that Target's ongoing evolution into an omnichannel retailer would push operating margins "somewhat lower than we've seen historically." That shift is hurting Walmart in exactly the same way, after all, so Target at least is in good company. And, fortunately for the company, the new, dramatically reduced corporate tax rate is pushing its overall profits higher even as its gross and operating margins decline.

The bull thesis for this stock has been that the retailer can afford to take a short-term profitability hit as it builds out its digital-selling infrastructure and competes more aggressively on price. From there, it should be able to use its stronger market position to deliver steadier, more robust long-term returns. And Target has made important progress in the hardest part of that optimistic narrative: achieving market-beating sales growth.

The company's final earnings report of the year will arrive in late November, and the key sales growth, gross profit margin, and customer traffic metrics  will indicate whether or not management's broad strategies are still working. As usual, a lot will come down to how well the retailer performs during the brutally competitive holiday shopping season.

The good news is that industry trends haven't been this strong in years, so the outlook is bright for companies like Target, which have positioned themselves to deliver the products, prices, and shopping experiences that customers crave in today's omnichannel shopping environment.