The digital advertising industry has struggled in 2022. As the Federal Reserve started hiking interest rates, more businesses feared an economic downturn. Thus, firms sought out ways to cut back spending. Since much of advertising is easy to cut, advertising stocks of all shapes and sizes felt the pinch of downturn fears. Even Alphabet (GOOG -1.43%) (GOOGL -1.40%) saw advertising demand drop. 

This year has been rough, but the further off an investor's time horizon, the more the current prices of advertising stocks look like a bargain. eMarketer forecasts that global digital ad spending will reach $876 billion by 2026 -- a 46% jump from the $602 billion expected in 2022. 

Here are my two favorite stocks for capitalizing on this emerging space.

The case for The Trade Desk

The Trade Desk (TTD 0.86%) is one of the few advertising stocks that has barely been affected by fears of an economic downturn. This advertising technology company helps advertisers find and purchase open ad space, and demand for its services has continued to fly higher. Third-quarter revenue soared 31% year over year to $395 million, and churn has remained below 5% -- as it has been for the past eight consecutive years.

How has The Trade Desk seen such success while other companies have stumbled? The reason lies within its independent nature. The Trade Desk provides advertisers with ad inventory from around the internet, whereas "walled gardens" like Alphabet only offer advertisers inventory from their own platforms, like Google.

The Trade Desk's openness gives advertisers a more diversified suite of biddable inventory and eliminates the conflict of interest that Alphabet and its advertising customers might have. Alphabet wants its advertisers to buy inventory on its own platform, even if that might not provide the highest return on investment for the advertiser. The Trade Desk, however, has no incentive to do that.

With this advantage in hand, The Trade Desk has seen relative stability. Advertisers might have to cut ad budgets, but they don't need to do so across the board. Rather, they can cut budgets more aggressively on some platforms while keeping spending stable on others (like The Trade Desk).

With over $485 million in trailing 12-month free cash flow, The Trade Desk has enough cash to continue innovating over the coming year, while rivals might be forced to pull back investment as the ad industry remains sluggish. This enables the company to continue capturing the considerable opportunity it has ahead.

The Trade Desk was battered in 2022 because of the industry downturn, even though its own performance has remained stable. Shares trade at 45 times free cash flow -- the company's lowest valuation since 2018, and far below its average valuation over the past five years of 158 times free cash flow. Given its massive market moving forward and its strong competitive edge, I'm excited about where The Trade Desk could go in 2023 and beyond.

The case for PubMatic 

Not all adtech stocks have performed as flawlessly as The Trade Desk, but that doesn't mean these businesses aren't investable. PubMatic (PUBM 3.73%), an adtech company working on behalf of publishers (those selling open ad inventory), has seen demand slow, with revenue anticipated to grow only 1% versus the year-ago period in the fourth quarter.

That said, there are still plenty of reasons to get excited about PubMatic. Top-line expansion might be slowing, but the company still expects revenue to rise 14% for the entire year -- outpacing the broader market.

The company's profits also remained robust. In Q3, it maintained a GAAP net income margin of 5% and a free cash flow margin of 16%. This profitability is far higher than what rivals like Magnite (MGNI 3.46%) achieved. Comparatively, Magnite had a GAAP net loss margin of 19% in Q3.

With healthy profits and top-line adoption that enables PubMatic to gain market share, you might think shares remained stable. That's not the case. Shares of PubMatic are down 62% in 2022, bringing the company's valuation down to just 16.4 times earnings -- a screaming bargain compared to other adtech rivals.

2022 wasn't pretty, but the company is weathering the storm. Long-term investors could see this as an excellent buying moment to get in on this lucrative advertising opportunity.