Online advertising companies have struggled for several years as Google and Facebook solidified their grip on digital dollars, slowing revenue for others.

Now, many ad tech companies and their investors are throwing up their hands.

Venture capital money going into ad tech startups is falling sharply, helping push a wave of consolidation. Financing reached a high of $2.92 billion in 2015, but this year, it is on pace to be less than half that, according to CB Insights, a financial research firm.

The number of independent ad tech companies has fallen 21 percent since 2013, to 185 as of the second quarter of 2018, according to LUMA Partners, which analyzes digital media and marketing.

And the pace of contraction has been quickening considerably. This summer has seen a flurry of activity, with AT&T buying online ad exchange company AppNexus in June, and private equity firm Vista Equity Partners acquiring a majority stake in Integral Ad Science the same month. In July, the Interpublic Group acquired data aggregator Acxiom’s marketing division for $2.3 billion.

“While all industries go through a maturation curve, this one faces a particular need for consolidation,” said Terry Kawaja, chief executive of LUMA Partners. “So many of these companies were not profitable.”

Although many consumers have never heard of ad tech firms, people’s online activity is influenced every day by these companies as they battle for a share of ad impressions on phones, tablets and laptops. The “Mad Men” style of advertising workers has been replaced by the “math men” of ad tech startups, which specialize in gathering data on consumer preferences.

Advertising, the economic juice behind the internet, has long been an attractive area for startups. During the past 10 years, the ease of forming companies and the availability of cheap venture capital led to a flood of ad tech startups, pushing boundaries on where and how ads were delivered. They introduced technologies such as the automation of ad buying — called programmatic advertising — and header bidding, in which many ad exchanges bid on publishers’ space simultaneously.

Overall spending for online ads continues to rise, to more than $88 billion in 2017, according to the Interactive Advertising Bureau, a trade group. But more than 90 percent of that growth in 2017 went to Google or Facebook.

Ari Paparo, chief executive of ad tech startup Beeswax, said he had noticed a distinct decline in venture capital funding for ad tech firms just in the past two years. “The private market is influenced by the public market, and you saw so many fail as publicly traded entities,” he said.

There were 260 deals between ad tech companies and venture capital firms in 2014 but only 122 in 2017, according to PitchBook. In the first half of 2018, there have been 53 deals.

The fear is that when investment dries up, innovation will die.

Small startups are crucial to the industry because they often serve as catalysts for technological advances, said Doug Knopper, one of the founders of ad tech platform FreeWheel, which was sold to Comcast in 2014.

“There’s still more innovation to come, but if VCs don’t put money into it because they don’t see a path to exit, does innovation stall?” he said, referring to venture capitalists.

Some are hoping a third big competitor could help the industry. Eric Adelman, president and one of the founders of Three Pillars Recruiting, said while the AT&T acquisition consolidates power in fewer places, the deal could help make AT&T a rival to Google and Facebook.

“Having three giants in the industry is much better than having two giants,” he said.

Amazon is also making inroads into advertising, with a new advertising arm, raising the possibility that it will become a top competitor. Its trove of data on consumer spending habits could make it a formidable opponent. The company recently reported that it generated $2.2 billion in revenue from its advertising business in the second quarter, more than twice as much as in the same period a year earlier.

Not all smaller players are giving up. Kevin Hunt, senior vice president of global marketing for the ad platform SpotX, is betting that his company’s focus on video advertising will set it apart.

“It’s important for companies who are in this space to be technically flexible, to make sure they have built a solid foundation that allows them to move as technology moves,” he said. Eric Franchi, one of the founders and a former executive at digital advertising company Undertone, isn’t giving up on ad tech. After software company Perion acquired Undertone in 2015, Franchi teamed up with Joe Zawadzki, chief executive of MediaMath, to fund an ad tech-focused venture-capital fund called MathCapital that helps the little guys.

“We want the best entrepreneurs that want to build ad tech companies to come to us,” Franchi said. “Over time, hopefully we can be a force for good in the space to help these companies get started.”

And even after Ben Barokas sold his company Admeld to Google in 2011, he decided to stay in the ad tech industry, creating a content compensation platform called Sourcepoint.

“I think certainly Facebook and Google are hoovering up the vast majority of growth,” he said. “That said, I believe in independent content creation. Those who invest appropriately are going to also win and attract advertising dollars.”