When President Obama’s campaign strategists tried to squeeze every last drop of efficiency out of their $300 million television advertising budget, they chose to do something un­or­tho­dox: They stopped worrying about which shows featured their commercials.

Most campaigns buy airtime based on television ratings for different demographic groups, selecting the shows they think likely voters will watch. In their attempts to find new efficiency, Obama aides threw that conventional wisdom out the window — instead choosing airtime only by the time of day and the channel.

The result was a system they called “the optimizer” that took into account information gathered from door-knockers and phone canvassers when they picked whether to advertise on, say, ESPN or TV Land.

“The optimizer doesn’t take into account the program at all,” said Carol Davidsen, who designed the system as the campaign’s director of media analytics. “But there’s a sanity check at the end to make sure that you’re not advertising on ‘Girls Gone Wild.’ ”

Advertising prices are set by the size of the audience. The most expensive advertising is during prime-time network shows with massive numbers of viewers. Those reach lots of targeted voters, but they’ll also waste money on people who have made up their minds. By finding the right programming, the campaign stitched together a big audience of targeted voters with less waste.

MAD MONEY | Presidential ad spending doubles in swing states

The team bought detailed data on TV viewing by millions of cable subscribers, showing which channels they were watching, sometimes on a second-by-second basis. The information — which is collected from set-top cable boxes and sold by a company called Rentrak — doesn’t show who was watching, but the campaign used a third-party company to match viewing data to its own internal list of voters and poll responses.

Davidsen said the campaign sought to reach two broad categories of voters: people who were still on the fence and Obama supporters who were sporadic voters.

The team’s calculations showed that it would get the most bang for its buck in some strange places: the Family Channel, the Food Network and the Hallmark Channel, among others. On broadcast TV, the campaign went for more daytime programs and late-night entertainment shows than Republican nominee Mitt Romney did.

The Obama team was on 60 channels during one week near the end of the campaign, compared with 18 for the Romney operation during the same period, according to cable advertising data.

Overall, the Obama campaign ran a more sophisticated targeting operation, said Tim Kay, political sales director for NCC Media, a consortium of cable operators.

“With Romney, they went after pure tonnage,” Kay said. “With Obama, you see them capturing those niche audiences. They bought a lot of networks that we would consider second or third tier.”

Obama’s campaign also would target cable operators serving small towns, while Romney tended to focus on media markets spanning several counties.

“I would agree they have done something new and interesting,” said Will Feltus, a Republican media buyer who worked for George W. Bush’s reelection campaign in 2004. “They didn’t invent the wheel, but they put some better ball bearings on it, that’s for sure.”

Part of the reason for Obama’s success in pushing the envelope was that he was flush with resources from the start and didn’t face a primary challenger. The campaign decided to try the new approach more than a year ago, when Romney was battling Texas Gov. Rick Perry in the GOP primary.

Nor was it cheap. The campaign paid at least $359,000 for Rentrak data and $70,500 to the Buckeye CableSystem, which serves part of Ohio, for data on its viewers, disclosure reports show.

Using set-top boxes allowed for much more data and also higher accuracy. Nielsen Media Research ratings, which are more commonly used, are based on surveys that are still done with a written diary in some markets.

Overall, Obama officials estimate they were able to get about 10 percent to 20 percent more efficient use of their money using the optimizer by piecing together small audiences.

“In the past we might have said, ‘Gee, there’s not enough people watching there — it’s not worth the money,’” said Jim Margolis, one of Obama’s top media consultants. “There’s a certain group that we want to speak to and you can reach them lots of different ways.”