Just four years ago, North Dakota Democrat Heidi Heitkamp was elected to the Senate at the same time that her state was voting solidly for Republican Mitt Romney for president. Does her story give this cycle’s endangered GOP senators a roadmap to victory even if Donald Trump gets trounced in their states?

First, the facts.

Heitkamp received 50.2 percent of the vote in her race, while incumbent President Obama received just 38.7 percent in North Dakota. She ran 11.5 percentage points ahead of the president in the Peace Garden state, a remarkable showing.

Now 60, Heitkamp had served as state attorney general for eight years and, before that, as state tax commissioner. She ran for governor, unsuccessfully, in 2000, and drew some added attention when she was diagnosed with breast cancer during the race.

After that loss, she took a job as director of the Dakota Gasification Company’s Great Plains Synfuels Plant. She served in that position until her Senate run.

Heitkamp was and is a terrific candidate – personable, down to earth, knowledgeable, funny and bright. She knows how to work a crowd but also how to talk one-on-one with voters and reporters.

This cycle’s Republican Senate incumbents and open seat candidates in competitive contests should take note of her campaign. In some ways, they should face an easier road than Heitkamp did. After all, she was running in a very Republican state four years ago, while Sens. Kelly Ayotte (R-N.H.), Rob Portman (R-Ohio), Ron Johnson (R-Wisc.) and Pat Toomey (R-Pa.) are running this year in toss-up or only slightly blue states.

Heitkamp’s opponent, Rick Berg, co-founded a very successful real estate management firm, Goldmark Property Management. He served in the North Dakota legislature for more than two decades, eventually winning a seat in Congress in 2012.  That race, in which he defeated veteran Democratic congressman Earl Pomeroy, was bitter, and Berg ended his bid with very high negatives, as well as the victory.

Why did Heitkamp win?

My long-time colleague Nathan Gonzales of the Rothenberg & Gonzales Political Report wrote a detailed post-mortem of the Senate race and identified a number of factors.

First, while Republican strategists thought they had a smoking gun in a comment that Heitkamp made – she said that “Barack Obama’s gonna be amazing” – Republicans found they had little other ammunition against her.

More importantly, Heitkamp’s strong support for the Keystone pipeline, and her general pro-development stance on energy, put her in opposition to Obama.

So while the GOP’s main strategy was to link her to the president, she had a high-profile example of her differences with him. (A radio spot with former North Dakota Democratic Sens. Kent Conrad and Byron Dorgan is a perfect example of how she documented her political independence.)

Second, Democrats successfully made Berg’s relationship with Goldmark into a major issue. Democrats attacked the company, which managed thousands of rental units in the state, for numerous violations and tenant complaints. Berg’s campaign didn’t respond effectively, keeping the Republican nominee (who already had high negatives) on the defensive.

Third, tactics and strategy can be important, and they both benefited Heitkamp. While Berg aired a flight of TV spots in February and March to boost his image, he then dropped off the airways until late June. Money was an issue, and the campaign and the National Republican Senatorial Committee argued about how the campaign should proceed.

Heitkamp’s campaign rolled the dice and decided to go up with Mark Putman-produced TV spots in late March, staying on the air for the three months when Berg was dark. The campaign’s positive spots probably helped inoculate Heitkamp against future attacks, while some Democratic Senatorial Campaign Committee negative ads attacking Berg added to his problems.

Finally, Heitkamp simply was a far better candidate and had far better television commercials than Berg, according to strategists on both sides of the aisle.

Ultimately, the GOP’s strategy was almost entirely about tying Heitkamp to Obama. Republican political operatives assumed that the president would be toxic in the state and that undecided voters late in the race would ultimately go their way.

But Heitkamp had one big issue difference with Obama, and possibly because she was better liked than Berg, voters gave her the benefit of the doubt when she stressed that she would be an independent voice for North Dakota.

Just as important, Democrats kept Berg on the defensive over Goldmark, even though he should have quickly answered the charges against the company, and against him, and moved the debate onto more favorable terrain for him.

North Dakota has a small population, and Heitkamp entered her race relatively well-known and well-liked. She had never served in federal office, so she didn’t have a voting record on some of the most divisive, partisan issues of the day.

Ohio, Wisconsin and Pennsylvania have large populations, so it is more difficult for politicians in those states to stay connected to the voters. And the incumbent Republicans have extensive voting records to defend.

Luckily for Portman, Johnson and Ayotte, they are running against veteran Democratic officeholders, some of whom have records in Congress. Those Republicans must keep their opponents on the defensive, just as those Democrats will try to keep the Republicans back on their heels.

The key to surviving a bad year for the GOP could be whether Republican senators in tough states have an issue or two they can use to document their political independence. For Toomey, that could be guns (especially now after the Orlando shooting). For Ayotte, it might be the environment.

But in all cases, the question is whether they did enough to demonstrate their independence.

Obviously, how well or poorly the GOP’s top of the ticket does will affect the prospects of vulnerable (and not yet vulnerable) Republican senators seeking re-election. The more neutral the national environment, the more likely Republican losses can be kept to three or fewer.

And that is what Republicans need to keep control of the Senate in 2017.

Stuart Rothenberg writes about the politics of the presidential and congressional races.