When Donald Trump took the stage last month in Fayetteville, N.C., to support Republican candidate Dan Bishop in a special election, thousands of people showed up.

Mr. Bishop was seeking their support. An outside Republican group was looking for something more. It wanted their data.

Unknown to the crowd, the Committee to Defend the President, a Republican political-action committee that supports Mr. Trump, had hired a company to collect unique identification numbers from attendees’ smartphones that evening, based on location data those phones were sending to third parties. The goal was to target ads at people it could drive to the polls the next day. Mr. Bishop won by about 3,800 votes.

The PAC now plans to use the technique, which is called geofencing, in the run-up to the 2020 presidential election in about half a dozen swing states to find people who may not be registered to vote, said its chairman, Ted Harvey.

“It’s another aggressive, on-the-ground effort to get those people identified,” Mr. Harvey said.