Like a polite guest at a dinner party, the advertising industry typically avoids bringing up religion. But there are some advertisers — including Ram Trucks and the smartphone accessories company Mophie — that have made God or prayer a part of their campaigns, albeit very carefully.

It is a high-risk, high-reward strategy, said John Hegarty, a founder of the Bartle Bogle Hegarty ad agency in London. If done right, it can inspire religious or spiritually minded consumers to act; but if done wrong, it can alienate an audience, he said.

McDonald’s combined messages like “God protect the USA” and “God gave us a miracle” with those like “We remember 9/11” in a 60-second television commercial early this year. During Super Bowl XLVII in 2013, Ram Trucks connected religion to pickup trucks in a spot that used the slogan “So God made a farmer.”

With a voice-over by Paul Harvey, the two-minute Ram Trucks commercial by the Richards Group, an ad agency based in Dallas, was viewed 18 million times in 10 days.

The best part was the “outpouring of heartfelt thanks and appreciation” from real farmers and their families, said Marissa Hunter, head of Ram advertising at Chrysler.

“To hear people say that we did an honest and pure job of capturing the essence of who they are is a very high compliment,” said Hunter, who named her puppy Farmer after the spot.

Currently, Tennessee Titans quarterback Marcus Mariota is appearing in ads for Saint Thomas Health, a chain of Catholic hospitals in Tennessee. In one spot, Mariota taps his heart three times — for his mother, father and brother — then points to the heavens to give thanks. The tagline, “Nothing shall be impossible,” is a quotation from the Gospel of Luke.

A small number of consumers were offended by the overt Christian symbolism, said Shari Day, chief executive officer of Bohan Advertising, which created the spot, but they were outnumbered by consumers who praised the faith-based ads. A member of the team working on the campaign came up with the tagline after hearing a sermon in church, Day said.

Some campaigns are much more subtle. Hegarty and Bartle Bogle Hegarty recently collaborated with the director Richard Curtis (“Four Weddings and a Funeral,” “Love Actually”) on an animated ad for Project Everyone — an effort to fight poverty, inequality, and climate change — that aired in movie theaters around the world.

The actor Liam Neeson provides a voice-over in the commercial, and although external communications about the ad refer to Neeson as the “voice of God,” there is no reference to that or religion in the spot.

“He has a lovely tone of voice that carries authority,” Hegarty said of Neeson. “It’s a weird thing that some people have. It’s godlike in its execution and deliverance.”

What is a riskier creative strategy? Trying to use God for laughs. Mophie aired its apocalyptic but humorous “All-Powerless” commercial during NBC’s broadcast of Super Bowl XLIX on Feb. 1.

The Mophie spot, by the ad agency Deutsch, shows snowstorms in Africa, burning bushes, and dogs walking humans. The reason for the chaos is that God’s smartphone battery has run out of power.

“Gosh darn it,” says the actor who represents God. The tagline: “When your phone dies, God knows what can happen.”

Mike Sheldon, chief executive officer of Deutsch North America, says the spot works because it is more about how people feel when their phones die, as if the world is ending, than it is about theology.

Mophie’s Super Bowl spot was shared, liked, or mentioned 41 million times across social media. The commercial has been viewed more than 5.7 million times on YouTube.

“He’s the only endorser you can find with 100 percent awareness — and no cost for the talent,” Sheldon said of God. “There’s no clearance, no network issues. You just have to believe that God, like the rest of us, uses a smartphone to run his life.”

But commercials perceived as blasphemous can face a fierce reaction.

The energy-drink maker Red Bull was forced to stop running an animated commercial in 2012 after heavy criticism. The ad, which aired in South Africa, portrayed Jesus explaining that there was nothing miraculous about him walking on water; he was stepping across hidden stones. But then he trips and gets wet. “Oh, Jesus,” he says. Authorities in Brazil threatened to ban the ad.

“We did not set out to offend anyone with it,” said Patrice Radden, a Red Bull spokeswoman. “However, having heard the response to it, we very quickly accepted that this was the unintended consequence, apologized, and immediately replaced it with another advertisement.” She added that the commercial never made it to the US market.

According to a study by the Pew Research Center, the number of Americans who identified as atheist or agnostic rose to 23 percent in 2014 from 16 percent in 2007.

Still, some marketers, like Day of Bohan, say they think many people still yearn for some sort of spiritual connection. But whether they want that connection to come from an advertisement is another question entirely.

“There are moments in time when brands really do need to stand back and be very, very careful about how they’re trying to impose themselves or get in on a conversation,” Hegarty said.