Donald Trump delivers inflammatory remarks about Mexican immigrants while he announces his run for president in June. Big businesses have denounced him. (Richard Drew/AP)

When Donald Trump called Mexican immigrants rapists and drug dealers while announcing his presidential run, it wasn’t his fellow Republicans, but companies such as NBCUniversal and Macy’s that most closely held his feet to the fire.

And while South Carolina politicians debated whether the Confederate flag should come down at the state’s capitol complex, Wal-Mart and Sears were already rushing to remove it from their shelves and Web sites.

Big businesses have lately been proactive, even aggressive, in taking a stand on the social and political issues that have given new fire to America’s long-simmering culture wars. From trumpeting their support for same-sex marriage on social media to ­urging Congress to modernize the nation’s immigration system, some of America’s biggest brands are coming off the sidelines to wade into contentious policy debates, a change in posture that reflects shifting customer expectations.

“Consumers have been judging companies more and more by their social policies, their economic policies; that’s become a big part of decision-making” of where they spend their money, said George Belch, a professor who studies marketing strategy at San Diego State University.

People hold signs on Wednesday in front of Macy's Herald Square flagship store in New York, supporting the company’s severing of ties with Trump. (Kathy Willens/AP)

This shift is not just a feel-good measure, analysts said, but often good business.

When department store giant Macy’s moved Wednesday to sever its business ties with Trump, the company said it was disappointed and distressed” by his “disparaging characterizations” of Mexican immigrants.

In a statement, Trump blamed the Macy’s move on “pressure being put on them by outside sources.” An online petition calling for the end of Trump’s line gained more than 728,000 signatures, and Latino advocacy group demanded that the chain “take a stand against discrimination.”

Trump also painted the breakup as partially his idea, in much the same way he did when, earlier this week, NBCUniversal parted ways with him, saying it would no longer air his Miss USA and Miss Universe beauty pageants.

“While selling Trump ties and shirts at Macy’s is a small business in terms of dollar volume,” Trump said, “my principles are far more important and therefore much more valuable.”

Macy’s had clear incentives to walk away from Trump, whose menswear line it has carried since 2004. The chain has been especially focused on winning over Latino shoppers. The company last month said its new private-label line designed to appeal to Latina women, a collaboration with Latina pop superstar Thalia Sodi, has so far been a “huge success.”

Just as the Macy’s move was decisive, so too were the actions taken last week by several retailers to get rid of merchandise bearing the Confederate flag after nine people were killed in a Charleston church in what authorities have called a racist hate crime.

While Sears did not carry any Confederate-flag-emblazoned items in its stores, it did have a small number of them on its online marketplace, which is open to third-party sellers. Chris Brathwaite, a company spokesman, said as soon as Sears heard rival Wal-Mart was pulling such items, it moved quickly to evaluate its own policies and ultimately decided to get rid of items with Confederate-flag imagery.

“It didn’t take us long, we were out in front of [it]. We acted before people had the opportunity to react,” Brathwaite said.

There has been a steady drumbeat of cases recently in which big businesses put their muscle behind a social issue.

The U.S. Chamber of Commerce, in letters signed by Apple, McDonald’s and Marriott, as well as hundreds of other businesses, urged Congress last year to swiftly modernize America’s immigration system. When Apple chief executive Tim Cook publicly declared that he was gay, he reinforced the tech giant’s position as a central voice on discrimination and human rights issues.

And few companies have shown this symbolic sweep as loudly and surprisingly as Wal-Mart, whose long reign as the world’s biggest retailer has been largely marked by virtual silence on social issues.

So far this year, the Bentonville, Ark.-based company has vigorously fought against that state’s religious freedom law, which critics said would have allowed businesses to refuse service to gay customers, banished Confederate-flag bandannas, swimsuits, belt buckles and other merchandise from its shelves.

Wal-Mart’s resistance to the Arkansas legislation was credited with turning the political tide against the bill in its home state. It was later passed with amended language to address opponents concerns. Chief executive Doug McMillon, in a statement in March, said the law threatened to “undermine the spirit of inclusion . . . and does not reflect the values we proudly uphold.”

The massive chain’s visible resistance to the Confederate flag may yet bring broader impact. As Charles Fishman, author of “The Wal-Mart Effect,” told The Washington Post last week, the company “is not just following the cultural conversation, they’re shaping it.”

Corporate America’s new strategy toward social issues has been hatched at a time when social media is creating a real-time barometer for consumers’ reactions to news events or product issues.

“In the past, decisions like this would’ve been a little bit more seat-of-the-pants,” Belch said. “Today, every company has ­social-media monitoring tools in place” and “they’re constantly out there looking for what’s being said.”

They’re not just closely watching that social-media conversation, but in some cases, looking to be a part of it. Major brands including Gap, Target and Procter & Gamble took to Twitter last week with rainbow-bedecked messages expressing support for the Supreme Court’s decision on same-sex marriage.

To be sure, these companies are not necessarily walking out on an especially precarious limb when they offer up their support for social or political causes. For example, polls show about 60 percent of Americans support same-sex marriage.

And yet these moves are not without risks. Starbucks, for example, abandoned a campaign last year to have its baristas chat up customers about race relations at the checkout counter. When the initiative drew criticism from customers who didn’t want a side of politics with their frappuccino, the company said workers no longer needed to write #racetogether on customers’ coffee cups.