Earlier this summer, President Trump discovered the provocative and politically incorrect campaign commercials of Georgia gubernatorial candidate Brian Kemp and began to contemplate whether to endorse him, asking Georgians working in his administration if Kemp was “a good guy.”

The endorsement arrived last week via Twitter, to the utter surprise of Kemp, at that moment in the midst of a news conference announcing far less significant support. The imprimatur helped Kemp amass a better than 2-to-1 runoff victory Tuesday over the state’s lieutenant governor, who had won the May primary and was seen as the stronger general-election candidate.

Over the past few months, Trump has fired off endorsements for 14 primary candidates in New York, California, Mississippi, South Carolina, Nevada, Missouri, Minnesota, Alabama, Florida, Georgia and Kansas. Of the nine candidates who have already had their primaries, all have won — victories for which Trump often claims credit. The president is waiting to see whether he correctly picked the primary winner in Florida’s contentious gubernatorial race.

His decisions sometimes hinge on disciplined study by his staff, sometimes on Trump’s gut reaction to a candidate’s message. Sometimes he has created a wave for a candidate, as the party’s most dominant figure, and sometimes he has surfed an existing one.

Just hours before the polls closed in South Carolina’s June 12 primary, Trump suddenly tweeted an endorsement for Katie Arrington, the Republican already poised to defeat Rep. Mark Sanford, a longtime Trump nemesis. The next morning, Trump tweeted: “My political representatives didn’t want me to get involved in the Mark Sanford primary thinking that Sanford would easily win — but with a few hours left I felt that Katie was such a good candidate, and Sanford was so bad, I had to give it a shot. Congrats to Katie Arrington!”

In the Georgia race, Trump sided with the eventual winner as Kemp was gaining ground on Lt. Gov. Casey Cagle, but the president’s support undoubtedly contributed to Kemp’s romp. An internal tracking poll used by Cagle’s campaign shows that Cagle’s favorability rating suddenly tanked the day after Trump’s endorsement.

The subtext of the Republican primaries this year has been the quest for a Trump endorsement, or at the very least denying the endorsement to an opponent. At times, candidates have crafted old Trump statements into what appear to be endorsements, for the benefit of voters who want to know where the president stands.

In Arizona, for example, Trump’s political aides have begged him to stay out of a U.S. Senate primary race that features three Republicans: former state lawmaker and conservative activist Kelli Ward; Joe Arpaio, the former Maricopa County sheriff and longtime Trump defender; and Rep. Martha McSally, who did not endorse Trump in 2016 but has been talking up her connections to the White House on the campaign trail.

The aides fear that Trump will endorse either Ward or Arpaio, who are seen as weaker general-election candidates.

Nearly a year ago, when Ward was the only announced candidate — Sen. Jeff Flake had yet to announce he would not run again — Trump tweeted: “Great to see that Dr. Kelli Ward is running against Flake Jeff Flake, who is WEAK on borders, crime and a non-factor in Senate. He’s toxic!”

Ward has treated that August 2017 message as an endorsement of sorts and, earlier this week, tweeted a quote from it, along with a photo of herself with the president.

In Nevada’s 3rd Congressional District, which is south of Las Vegas, three Republican candidates spent part of a May debate tussling over whether a March 16 tweet from the president about one of the candidates, Danny Tarkanian, could be considered an endorsement.

Tarkanian had contemplated challenging Sen. Dean Heller (R), and Trump urged him not to do so, tweeting: “It would be great for the Republican Party of Nevada, and it’s unity if good guy Danny Tarkanian would run for Congress and Dean Heller, who is doing a really good job, could run for Senate unopposed!”

“An endorsement is when you have people that are in the race and the president picks one of those people out to support them,” Tarkanian said. “In this case, the president asked me specifically to run in this Congressional District 3 race. So I think that’s even more than an endorsement.”

His rivals disagreed.

“The language never said, ‘I endorse Danny Tarkanian,’ ” said Scott Hammond, a state senator.

“The tweet did not use the word ‘endorsement’ or ‘support,’ ” said Michelle Mortensen, a former television journalist.

In the end, Trump did not weigh in on the House contest, and Tarkanian won the June 12 primary.

The White House has a formal process for endorsements: Trump meets a few times a month with a political team armed with written presentations that feature photos of candidates, their positions on certain issues, Trump’s popularity in their districts and an assessment of how loyal they have been to Trump and his positions. Sometimes the team will call candidates from the Oval Office, according to aides.

But as with all other aspects of the presidency, Trump’s informal musings often take over, with the president responding to things he sees on television or hears in phone calls with friends or conversations with staff members who follow races in their home states.

Often, as in Kemp’s case, the president’s opening question is a simple one: Is this candidate a “good guy”?

The formal process tends to push Trump in the direction of Republican candidates who are favored by the party’s establishment over candidates who are running outsider campaigns modeled after his own.

Such was the case last year, when Trump at first endorsed appointed Sen. Luther Strange (R-Ala.) in a special election. Trump’s discomfort was notable — he publicly waffled at a rally meant to boost Strange, telling the audience: “I might have made a mistake.” When Strange lost the GOP primary, Trump endorsed a candidate more in his image, former judge Roy Moore — who went on to lose the general election to Democrat Doug Jones.

That experience stayed with Trump, who has referred to it often. A day before West Virginia’s Senate primary, Trump urged Republicans to vote for either Rep. Evan Jenkins or Attorney General Patrick Morrisey but not Don Blankenship, a former coal mine owner who was convicted on a misdemeanor charge of conspiring to violate federal mine safety standards after a deadly explosion in a mine operated by his company. Trump tweeted that Blankenship “can’t win the General Election in your State...No way! Remember Alabama.” Morrisey won the primary.

Trump also played it safe when, a month before the primary in New York’s 11th District, he endorsed Rep. Daniel Donovan instead of his Trump-like challenger, former congressman and ex-convict Michael Grimm. “Very importantly, @RepDanDonovan will win for the Republicans in November…and his opponent will not. Remember Alabama,” Trump tweeted. Donovan then won.

But that approach did not carry over to the Georgia race between Kemp, the state’s secretary of state, who never formally endorsed Trump during the 2016 election, and Cagle, who increasingly tried to act and sound like the president in the final days of the race.

Cagle’s campaign staff had hoped the president would help save his campaign with an endorsement, as polls had shown that Cagle would be more likely to win the general election and beat the Democratic candidate, Stacey Abrams.

But Trump admired Kemp’s hard-line immigration stances — and his campaign ads, so exaggerated that some outside of Georgia at first mistook them for satire.

In one, Kemp explained that his “chain saw’s ready to rip up some regulations” and that he drives “a big truck, just in case I need to round up criminal illegals and take ’em home myself” — a line followed up with: “Yup, I just said that.” In another, Kemp sat, shotgun in hand, next to a teenage boy named Jake and made the young man recite his campaign platforms and his two rules for dating one of his daughters: “Respect” and “a healthy appreciation for the Second Amendment, sir.”

For weeks, whenever the president encountered a staffer or visitor with a tie to Georgia, he would ask about Kemp. Georgians who were queried included Vice President Pence’s chief of staff, Nick Ayers, and Agriculture Secretary Sonny Perdue. Soon after Perdue attended a Cabinet meeting at the White House last week, the president tweeted his “full and total endorsement” for Kemp.

Pence’s office scurried to organize a Saturday afternoon rally with Kemp in central Georgia — where, in about 20 minutes, Pence called Kemp a “good man” nine times.

In his victory speech Tuesday night, Kemp lavishly thanked the president and vice president.

“We cannot forget that tweet that we heard around Georgia,” Kemp said.

The endorsement, he said, “poured gasoline on the fire and fueled the Kemp surge to victory.”