Fresh off an $850 million acquisition by Yahoo, Right Media CEO Michael Walrath and board members Noah and Jonah Goodhart thought their next big ad tech venture was a crowdsourced marketplace meant to connect ad creators with brands. Despite their respect in the ad industry and connections to the largest investors in Silicon Valley and some of media’s biggest, the group’s initial product floundered.

But as they met with potential clients, they noticed analytics questions kept cropping up. So rather than going down with a sinking ship, they shifted their company, Moat, to focus on ad measurement, which proved to be prophetic when it reportedly sold for more than $850 million to Oracle five years later.

After mastering the ad tech pivot, Moat became an ad measurement juggernaut with more than 600 clients. It pulled off this shift by using its connections to set up meetings with industry bigwigs, remaining open to changing its focus based on feedback, identifying an industry trend early on, continually releasing new products once it found its niche and getting lucky that demand for ad measurement didn’t level off before the company got sold. As Moat’s head count grew from 10 to more than 300 and it raised just under $70 million over the past seven years, it also benefited from pivoting while it had just 20 employees.

“The creative crowdsourcing just didn’t work, so like good entrepreneurs, they found another market,” said AppNexus CEO Brian O’Kelley, who was an angel investor in Moat. “It was fortunate that the creative tool didn’t work out early on because VCs would rather invest in a startup without baggage.”

At early ad exchange Right Media, Jonah Goodhart noticed that most programmatic ads came from direct-response advertisers, and few national brands were using automated platforms to buy inventory. Jonah Goodhart, who became Moat’s CEO, thought the roadblock preventing brands from buying programmatically was that brands didn’t know what their online creative should look like.

So in Moat’s first year, it built a search engine for display ads that made it easy for people to find ads that belonged to specific companies. The ad search engine was tied to a crowdsourced marketplace where ad creators that got approved by Moat would submit ads for brands to use.

During 2011 and 2012, Jonah Goodhart had about 1,000 meetings with publishers, agencies, brands and ad tech firms to see who was interested in Moat’s product. He relied on Moat’s deep connections to the industry — Moat’s investors include Peter Thiel’s Founders Fund, MediaMath CEO Joe Zawadzki and Lerer Hippeau, which includes HuffPost co-founder Kenneth Lerer and former Ziff Davis CEO Eric Hippeau as managing partners — to get face time with potential clients.

“The feedback we got from brands was they thought this was an additional fee to their creative agency, and they saw it as a net cost,” Jonah Goodhart said. “And creative agencies didn’t want us to do this because that’s what they do.”

While these meetings indicated there wasn’t demand for Moat’s ad marketplace, Jonah Goodhart noticed people were asking lots of questions about the analytics Moat was putting together, like heat maps that measured user attention by tracking how long a mouse hovered over an ad. Another thing that convinced Moat to pivot was the Making Measurement Make Sense initiative, launched in 2011 by the Interactive Advertising Bureau, the Association of National Advertisers and the American Association of Advertising Agencies, which highlighted the inadequacies of digital ad measurement and prompted panels at industry events that drove demand for measurement products.

As buzzwords like viewability emerged, Moat sensed an opportunity and shifted its business to focus on ad measurement. In April 2012, Forbes became Moat’s first publisher client to pay for its measurement products. About a year later, Kellogg’s became Moat’s first brand client. For a few years, nearly 90 percent of Moat’s clients were publishers. Today, the company’s mix of supply-side and demand-side clients is about even, Jonah Goodhart said.

Ad tech companies like Moat that sustain success over several years often share a willingness to not be beholden to the sunk costs of their original business model, said Nick MacShane, founder of investment bank Progress Partners, which invested in ad tech companies like MediaMath, Dstillery and Moat competitor Integral Ad Science through its VC arm. For example, Index Exchange is now the preferred header-bidding vendor for many publishers, but this was only after it pivoted from being an ad network and started billing on transparent fixed fees. Meanwhile, demand-side platforms that maintained high margins are getting squeezed as ad buyers move to self-service models with lower fees, and Rubicon Project hasn’t recovered since it was slow to header bidding, MacShane said.

The key to thriving in ad tech is to dominate your niche, O’Kelley said. After Moat found its groove in ad measurement, it grew by releasing products around emerging trends. It complemented its viewability and anti-fraud products with brand safety and offline sales trackers after those topics became all the rage.

“Your timing has to be right, and the gods have to grant favor on you,” said Sourcepoint CEO Ben Barokas, who was president of ad tech firm Admeld when it sold to Google for $400 million in 2011. “For an exit like that, the acquirer has to want to own that particular thing at that particular time.”