“In the olden days, the consequences of planning were great, so we’d spend nine months before air date” doing research, says Barry Lowenthal, the president of the Media Kitchen, a media planning and buying company that, like Varick, is a unit of MDC Partners. “Then, nine months after we’d been running the ad, we’d finally figure out whether it was working or not.”

Online, though, advertisers get instant measurements and can make instant changes to a media plan.

Varick and its handful of competitors cement their strategies around a system called exchanges, a mechanism that helps online publishers like NBC.com or Yahoo.com sell ad space. While publishers have some ad space no company would bid on in advance  few advertisers would book a random Yahoo mail page, for instance  publishers still want to show an ad when someone loads that page. So the publishers let an ad exchange like Right Media, from Yahoo, or DoubleClick Advertising Exchange, from Google, sell that space instantly, through an electronic auction, and get a cut of sales.

Such random, seemingly unwanted space could be virtually worthless. But because ad agencies can now use multiple sources to gather very specific demographic data about visitors, such space gains value and can be brokered on an exchange.

Among the sources agencies rely on for data-mining is information gathered from other sites. Imagine that every time someone entered a store while shopping, she received a stamp on her hand. By the time she got to Macy’s, the clerk could see she had visited Williams-Sonoma and Home Depot and could direct her to housewares. A similar principle is followed online.

When someone visits a site like Expedia or Autobytel.com, that site captures valuable information: Someone is a first-class traveler, for instance, or shopping for a hybrid car. Those sites have deals with data companies, like BlueKai and eXelate, to place a so-called cookie  a small text file  on that visitor’s hard drive, indicating those preferences. An advertiser like Varick bids on those cookies, instructing an exchange that it will pay a certain amount for an ad when a certain cookie is for sale.

Other companies, like Media6Degrees and 33Across, analyze the world of social media, using cookies and interaction data to find “lookalike” groups among friends on Facebook, Flickr or other social sites. Their theory is that friends share values and are likely to respond to similar marketing messages.

Finally, companies can add cookies for anyone who visits pages on their sites  if someone gets to the checkout page, then abandons his shopping cart, the company will probably pay lots of money to advertise to him again.