On any given day, the Trump campaign is plastering ads all over Facebook, YouTube and the millions of sites served by Google, hitting the kind of incendiary themes — immigrant invaders, the corrupt media — that play best on platforms where algorithms favor outrage and political campaigns are free to disregard facts.

Even seemingly ominous developments for Mr. Trump become fodder for his campaign. When news broke last month that congressional Democrats were opening an impeachment inquiry, the campaign responded with an advertising blitz aimed at firing up the president’s base.

The campaign slapped together an “Impeachment Poll” (sample question: “Do you agree that President Trump has done nothing wrong?”). It invited supporters to join the Official Impeachment Defense Task Force (“All you need to do is DONATE NOW!”). It produced a slick video laying out the debunked conspiracy theory about former Vice President Joseph R. Biden Jr. and Ukraine that is now at the center of the impeachment battle (“Learn the truth. Watch Now!”).

The onslaught overwhelmed the limited Democratic response. Mr. Biden’s campaign put up the stiffest resistance: It demanded Facebook take down the ad, only to be rebuffed. It then proceeded with plans to slashits online advertising budgetin favor of more television ads.

That campaigns are now being fought largely online is hardly a revelation, yet only one political party seems to have gotten the message. While the Trump campaign has put its digital operation firmly at the center of the president’s re-election effort, Democrats are struggling to internalize the lessons of the 2016 race and adapt to a political landscape shaped by social media.

Mr. Trump’s first campaign took far better advantage of Facebook and other platforms that reward narrowly targeted — and, arguably, nastier — messages. And while the president is now embattled on multiple fronts anddisfavored by a majority of Americansin most polls, he has one big advantage: His 2020 campaign, flush with cash, is poised to dominate online again, according to experts on both ends of the political spectrum, independent researchers and tech executives. The difference between the parties’ digital efforts, they said, runs far deeper than the distinction between an incumbent’s general-election operation and challengers’ primary campaigns.

The Trump team has spent the past three years building out its web operation. As a sign of its priorities, the 2016 digital director, Brad Parscale, is now leading the entire campaign. He is at the helm of what experts described as a sophisticated digital marketing effort, one that befits a relentlessly self-promoting candidate who honed his image, and broadcast it into national consciousness, on reality television.

The campaign under Mr. Parscale is focused on pushing its product — Mr. Trump — by churning out targeted ads, aggressively testing the content and collecting data to further refine its messages. It is selling hats, shirts and other gear, a strategy that yields yet more data, along with cash and, of course, walking campaign billboards.

“We see much less of that kind of experimentation with the Democratic candidates,” said Laura Edelson, a researcher at New York University who tracks political advertising on Facebook. “They’re running fewer ads. We don’t see the wide array of targeting.”

The Trump campaign, she said, “is like a supercar racing a little Volkswagen Bug.”

The Democrats would be the Volkswagen. They are largely running what other experts and political operatives compared to brand-loyalty campaigns, trying to sway moderates and offend as few people as possible, despite mounting research that suggestspersuasion ads have little to no impact on voters in a general election.

The candidates, to be sure, are collectively spending more on Facebook and Google than on television and are trying to target their ads — Mr. Biden’s tend to be seen by those born before 1975, for instance, while Senator Bernie Sanders’s are aimed at those born later. But without the same level of message testing and data collection, the Democrats’ efforts are not nearly as robust as Mr. Trump’s.

Democratic digital operatives say the problem is a party dominated by an aging professional political class that is too timid in the face of a fiercely partisan Republican machine. The Biden campaign’s decision to tack from digital to television, they say, is only the most glaring example of a party hung up on the kind of broad-based advertising that played well in the television age but fares poorly on social media.

The digital director of a prominent Democratic presidential campaign recounted how he was shut down by an older consultant when pressing for shorter, pithier ads that could drive clicks. “We don’t need any of your cinéma vérité clickbait,” the consultant snapped, according to the digital director, who spoke on the condition of anonymity to avoid risking his job.

Other digital consultants and campaign officials told similar stories, and complained that the Democratic establishment was too focused on winning over imagined moderates, instead of doing what the Trump campaign has done: firing up its base.

“It’s true that anodyne messaging doesn’t turn anyone off. But it doesn’t turn them on either,” said Elizabeth Spiers, who runs the Insurrection, a progressive digital strategy and polling firm.

Republicans are “not messaging around unity and civility, because those things don’t mobilize people,” Ms. Spiers said, adding that while everyone may want to live in a less divided country, “nobody takes time off work, gets in their car and drives to the polls to vote specifically for that.”

Facebook Favors the Angry

Far more than any other platform, Facebook is the focus for digital campaign spending, and it is in many ways even friendlier turf for Mr. Trump’s campaign than in 2016.

Since then, many younger, more liberal users have abandoned the platform in favor of Instagram, Snapchat and various private messaging apps, while older users — the type most likely to vote Republican — are still flocking to Facebook in droves. People over 65 now make up Facebook’s fastest-growing population in the United States, doubling their use of the platform since 2011, according to Gallup.

In a speech this year in Romania, Mr. Parscale recalled telling his team before the 2016 election that Facebook would allow the campaign to reach the “lost, forgotten people of America” with messages tailored to their interests.

“Millions of Americans, older people, are on the internet, watching pictures of their kids because they all moved to cities,” Mr. Parscale said. “If we can connect to them, we can change this election.”

Facebook also favors the kind of emotionally charged content that Mr. Trump’s campaign has proved adept at creating. Campaigns buy Facebook ads through an automated auction system, with each ad receiving an “engagement rate ranking” based on its predicted likelihood of being clicked, shared or commented on. The divisive themes of Mr. Trump’s campaign tend to generate more engagement than Democrats’ calmer, more policy-focused appeals. Often, the more incendiary the campaign, the further its dollars go.

Provocative ads also get shared more often, creating an organic boost that vaults them even further ahead of less inflammatory messages.

“There’s an algorithmic bias that inherently benefits hate and negativity and anger,” said Shomik Dutta, a digital strategist and a founder of Higher Ground Labs, an incubator for Democratic start-ups. “If anger has an algorithmic bias, then Donald Trump is the captain of that ship.”

A Facebook spokeswoman disputed the notion that ads got more visibility just because they were negative, and noted that users were able to flag offending ads for possible removal.

The company, since the 2016 election, has invested heavily to prevent Russian-style interference campaigns. It has built up its security and fact-checking teams, staffed a “war room” during key elections and changed its rules to crack down on misinformation and false news.

But it has left a critical loophole: Facebook’s fact-checking rulesdo not apply to political ads, letting candidates spread false or misleading claims. That has allowed Mr. Trump’s campaign to show ads that traditional TV networks have declined to air.

One recent video from the Trump campaign said that Mr. Biden had offered Ukraine $1 billion in aid if it killed an investigation into a company tied to his son. The video’s claims had already been debunked, andCNN refused to play it. But Facebook rejected the Biden campaign’s demand to take the ad down, arguing that it did not violate its policies.

At last count, the video has been viewed on the social network more than five million times.

The 2016 Playbook

In the wake of the 2016 election, some on the left sought an explanation for Mr. Trump’s victory in the idea that his campaign had used shadowy digital techniques inspired by military-style psychological warfare — a“Weaponized AI Propaganda Machine,” as one article described it — created by the defunct political consulting firm Cambridge Analytica. The theories around Cambridge Analytica have never been fully demonstrated,however, and there is a far less nefarious explanation: The Trump campaign simply made better use of standard commercial marketing tools, particularly Facebook’s own high-powered targeting products.

Aninternal Facebook reportwritten after the 2016 election noted that both the Trump and Clinton campaigns spent heavily on Facebook — $44 million for Mr. Trump versus $28 million for Hillary Clinton. “But Trump’s FB campaigns were more complex,” the memo said, and were better at using Facebook to bring in donations and find new voters. For instance, roughly 84 percent of the Trump ads focused on getting voters to take an action, such as donating, the report said. Only about half of Mrs. Clinton’s did.

At the same time, the Trump campaign sought to tailor its ads more precisely to specific voters, the report said, with a typical Trump message targeted at 2.5 million people, compared with eight million for the Clinton campaign. And the Trump team simply made more unique ads — 5.9 million versus 66,000.

“We were making hundreds of thousands” of variations on similar ads, Mr. Parscale told “60 Minutes” last year. “Changing language, words, colors.”

The idea, he said, was to find “what is it that makes it go, ‘Poof! I’m going to stop and look.’”

For the left, the Trump campaign’s mastery of social media in 2016 represented a sharp reversal. From the blogs of the mid-aughts to Netroots Nation, the digital activists who helped propel Barack Obama to victory in 2008 and 2012, the left was seen as the dominant digital force. The Democrats had an array of tech-savvy campaign veterans who were adept at data mining and digital organizing, and had overseen the creation of a handful of well-resourced digital consulting firms.

Starting with the 2016 primaries, the Trump campaign reversed the trend. While the more traditionally minded Republican operatives signed on to work for the party’s more traditional candidates, such as Jeb Bush, the Trump campaign found itself reliant on “the outliers, and a lot of them truly believed in digital,” said Zac Moffatt, chief executive of Targeted Victory, a Republican digital strategy firm. “It was a changing of the guard, strategically.”

The Republicans’ 2020 operation — with more than $150 million in cash on hand, according to the latest filings — appears to have picked up where it left off.

The Trump campaign’s intense testing of ads is one example. It posts dozens of variations of almost every ad to figure which plays best. Do voters respond better to a blue button or a green one? Are they more likely to click if its says “donate” or “contribute”? Will they more readily cough up cash for an impeachment defense fund or an impeachment defense task force?

The president’s re-election effort is also making use of strategies common in the e-commerce world, such as “zero touch” merchandise sales. T-shirts, posters and other paraphernalia are printed on demand and sent directly to buyers, with the campaign not required to make bulk orders or risk unsold inventory. Sales of these items amount to a lucrative source of campaign fund-raising, and the zero-touch technique allows the campaign to move fast — it was able tostart selling T-shirts that say “get over it” a day after the president’s acting chief of staff, Mick Mulvaney, told reporters to do just than when it came to Ukraine.

Perhaps most important, the Trump campaign is spending to make sure people see its ads, emails, texts, tweets and other content. In the week the impeachment inquiry was announced, for instance, the campaign spent nearly $2.3 million on Facebook and Google ads, according to data compiled by Acronym, a progressive digital strategy organization that tracks campaign spending. That is roughly four to five times what it spent on those platforms in previous weeks, and about half of what most Democratic front-runners have spent on Facebook and Google advertising over the entire course of their campaigns.

The president’s team has also invested heavily in YouTube, buying ads and counterprogramming his opponents. In June, during the first Democratic primary debates, the Trump campaign bought the YouTube “masthead” — a large ad that runs at the top of the site’s home page and can cost hundreds of thousands of dollars per day — to ensure that debate viewers would see it.

The Trump campaign “is always re-upping their ad buy. As soon as an ad runs out, another one goes in,” Ms. Edelson said, adding, “No one is waiting for next month’s marketing budget to kick in.”

Glamour Shots Only

Democrats are struggling to match more than the sheer volume of content coming out of the Trump campaign. Interviews with Democratic consultants and experts revealed a party deeply hesitant to match the Trump campaign’s intense and often angry partisan approach.

Most of the Democratic Party is “not even fighting last year’s war — the war that they’re fighting is 2012,” said David Goldstein, chief executive of Tovo Labs, a progressive digital consulting firm.

Mr. Goldstein offered an instructive anecdote from the 2018 midterm elections. That spring, Tovo signed on to do online fund-raising for Andrew Gillum, the Democratic candidate for governor in Florida. Tovo wanted to build on the work it had done the year before in Alabama, where it claimed to have depressed Republican turnout by running ads that showcased conservatives who opposed the far-right Senate candidate Roy Moore. The ads did not say they were being run by supporters of the eventual Democratic winner, Doug Jones.

Mr. Goldstein hoped to bring the same edge to Mr. Gillum’s campaign and came up with ads that “were really aggressive.”

“We wanted to provoke people,” he said.

One was a particularly buffoonish caricature of Mr. Trump holding the world in his palm. “As Florida goes in 2018, so goes the White House in 2020,” read the tagline.

The ad was aimed at far-left voters deemed most likely to be motivated by the prospect of pushing Mr. Trump from office, and the response rate was high, Mr. Goldstein said. But a few days after it went up, the campaign manager saw it and “freaked out.”

“This is entirely unacceptable,” the campaign manager, Brendan McPhillips, wrote in an email on April 6, 2018.

In Mr. Goldstein’s telling, the campaign manager feared offending voters whom Mr. Gillum hoped to sway. Mr. McPhillips was not mollified when Tovo explained that the ad was targeted only at voters thought to be deeply anti-Trump. He wanted ads that were focused on his candidate, not produced to elicit an emotional response with images the campaign considered crass.

Mr. McPhillips ordered Tovo to immediately stop running the ads. He said Tovo could only use images approved by the campaign. Tovo left soon thereafter.

The approved images — “standard glamour shots of the candidate” — would work for a newspaper ad or television spot, Mr. Goldstein said, but were not “going to drive clicks and provoke people to take action.”

Mr. Gillum narrowly lost the race.

Follow Matthew Rosenberg on Twitter at @AllMattNYT, and Kevin Roose at @kevinroose.