The best way to build wealth is to stay focused for the long term. When investing, that means identifying strong businesses that have carved out lasting competitive advantages and holding their stocks for a long time.

Let's have a closer look at two companies that simply dominate the digital advertising market: Alphabet (GOOG 0.66%) and Meta Platforms (META -0.65%).

Person holding a like button.

Image source: Getty Images.

Alphabet

Topping the list of tech stocks to buy for the long haul is Alphabet. It should come as no surprise, but Alphabet, the U.S.'s third-largest stock by market cap, has been a fantastic investment over the last 10 years.

For example, a $5,000 investment in Alphabet, made 10 years ago, would have grown to $23,600 today. That's a total return of 372%, or a compound annual growth rate (CAGR) of 16.8%. More to the point, there's every reason to think that Alphabet can duplicate this performance over the next 10 years, too. The company's legendary applications remain fixed in the popular consciousness. YouTube, Gmail, and Google Search are all indispensable for billions of worldwide users.

Financially, Alphabet's revenue and profits are staggering. The company generated $290 billion in revenue over the last 12 months and more than $156 billion in gross profit. Its balance sheet is rock-solid, with $118 billion in total cash and less than $30 billion in debt. What's more, analysts don't see any sign of weakness for Alphabet's business. Wall Street expects sales to grow 11% next year.  

While shares have certainly moved higher this year -- the stock is up 48% year to date -- it can still be argued that Alphabet shares remain cheap by historic standards. The stock trades at a price-to-free cash flow ratio of 25 times; that's below the five-year average of 29 times. At any rate, tech investors looking for a solid buy-and-hold stock should certainly consider Alphabet, given its commanding position within the industry.

Meta Platforms

Meta Platforms is another tech stock to own for the long haul. Like Alphabet, Meta operates primarily in the digital advertising market. And while it is true that another tech behemoth, Amazon, is taking digital ad share away from Alphabet and Meta, there's still plenty of juice left in the lemon for the traditional powers of Alphabet and Meta.

In its most recent quarter (the three months ending on June 30, 2023), Meta reported $32 billion in revenue, up 11% from a year earlier. Note that this came during a period of supposed pullback in digital ad spending. Simply put, Meta has a solid grip on the lucrative digital ad market, with an estimated 18%, second only to Alphabet's monster 39% share. Amazon, for reference, is a distant third with roughly 7%. 

The bounceback in revenue comes as Meta continues to trim estimates of capital expenditures (capex) spending. The company reduced its capex estimates for 2023 by $3 billion, to between $27 billion to $30 billion. That's in keeping with Meta's cost-cutting, which has helped boost the company's free cash flow to $24 billion over the last 12 months.

Granted, investors should be cautious, since Meta shares are no longer cheap. The stock trades at a price-to-earnings multiple of 35 -- significantly above its five-year average price-to-earnings (P/E) ratio of 25. Nevertheless, for those willing to buy and hold, Meta's top position in the digital ad market is good to pass up.