But glamorous as it was, the ad business wasn’t the best deal for the companies that were paying for the ads. The central problem was the conflation of audience and media outlet: When it ran an ad for razors, Gillette would have preferred to show the spot just to men who shaved regularly. But you couldn’t target men who shaved regularly.

“It wasn’t possible for us to be certain that we were reaching that audience, so we used the content of certain programming to define that audience,” said Brian Lesser, the chief executive of GroupM, a division of the advertising giant WPP. In other words, instead of targeting men, they’d run ads on shows they thought men liked to watch — a good enough solution, except for all the women and non-shavers who were also watching.

Digital advertising fundamentally altered this model. Through profiling, now ad companies know — or, at least, aim to know — exactly who is reading a certain site or watching a certain video. So instead of buying ads tied to a certain piece of content, companies can buy ads targeted exactly to an audience.

“Now we can get down to the level of an individual user and we can be certain that we’re targeting an ad to the same user across multiple devices,” Mr. Lesser said.

But it’s deeper than that. Ad companies don’t just know the user, but they also know the user’s context — for instance, whether you’re at work or at home, or whether you’re in the mood for shopping or not. All of this comes together in a real-time calculation as you wander around the digital world, from app to website to social feed. The computers are watching what you do and deciding which ads to serve you when. Often the ads are sold dynamically in an auction — different companies offer to pay different amounts to get your attention at different times.

There are some obvious downsides to this model. It relies on the profiling of users, which makes many people uncomfortable, even if the ad companies say that they do all of this anonymously and without invading your privacy.

It also raises an issue for brands. One consequence of this model is that it pays for a lot of content that wouldn’t have been funded under the old model — now a teenager can attract a few million followers on YouTube, sign up for the company’s revenue-sharing program and make money from all of the programmatic sponsors.