Supporters of gay marriage gather for a rally in January at the Utah State Capitol in Salt Lake City. (Rick Bowmer/AP)

Gay marriage opponents are losing court battles left and right, with judges in two states -- Indiana and Utah -- dealing them their latest setbacks just today.

But one place where gay marriage opponents are still getting traction: The primary ballot box.

The universe of Republican elected officials who support gay marriage is still small enough that, whenever one of them jumps on-board, they're quite likely to find themselves challenged in a primary. And more often than not, they have either lost or faced very tight races.

Rep. Richard Hanna (R-N.Y.) is the latest example. Hanna, who is one of just a handful of House Republicans to support gay marriage, withstood a conservative primary challenge on Tuesday, beating state Assemblywoman Claudia Tenney 53 percent to 47 percent. The race was closer than expected and one of the tightest congressional primaries this year.

There are three other recent examples of Republicans who strayed on gay marriage facing primaries:

  1. Indiana Republicans in May ousted two GOP state legislators who voted against a constitutional ban on gay marriage. State Rep. Kathy Heuer lost her primary 57 percent to 43 percent, while state Rep. Rebecca Kubacki lost hers 64 percent to 36 percent. Nine other House Republicans voted against the ban, but only one of them faced a primary challenge.
  2. In Illinois last year, three state House Republicans voted to legalize gay marriage. One of them won easily in the 2014 primaries, and another was nominated for state treasurer. The third, state Rep. Ron Sandack, won by just 154 votes, or about 1 percent.
  3. In New York in 2012, four GOP state senators voted in favor of gay marriage. One retired and another won his primary by 20 points. But among the other two, both lost their seats. State Sen. Roy McDonald lost his primary by 99 votes, while state Sen. Stephen Sarland won his primary by 107 votes. But Sarland's primary challenger ran in the general election on the Conservative Party line, taking 14 percent of the vote and throwing the race to the Democrat.

In total, of the 19 legislators above who didn't toe the conservative line on gay marriage, 10 faced primaries, four lost and two others faced pretty tight races.

And if you exclude Indiana (in which the 11 Republican defectors weren't technically voting *for* gay marriage but rather against a constitutional ban), most gay marriage supporters at least faced a tight primary, and half lost.

In sum, voting for gay marriage is hardly a death wish. But it's a very good way to draw yourself a primary challenge, and even the pro-gay marriage Republicans who have survived did so in some cases by quite narrow margins -- in contrast to the average incumbent who is either unopposed or skates by easily.

Yes, Hanna won. But if you're one of his GOP colleagues and you see how close his race was -- very few incumbents are held below 60 percent, much less in the low 50s -- it's likely to give you pause in your own personal "evolution" on the gay marriage issue.

The kicker in all of this is that the social conservative movement isn't as powerful as it once was, and it doesn't have the same desire to press its case on gay marriage as it once did. So if and when Republicans start supporting gay marriage in larger numbers, it's going to be hard for social conservatives to target all of the deserters.

But until then, nobody wants to be the early gay marriage supporter whom social conservatives decide to make an example of. Hanna won Tuesday, but his win probably isn't all that encouraging for like-minded pols.