The way it often works is that a President doesn't travel explicitly for campaign purposes.
The trip is often billed as official business. In other words, the trip would supposedly occur regardless of any political campaign or cause.
The thinking then goes, "but hey, what the hell, while I'm there, let's do a fund-raiser with George Clooney" or "... a rally for Senator Ted Cruz".
There are variations of this paradigm, but the basic concept is generally the same.
This allows the taxpayers to "legitimately" pay for all expenses relating to the President's trip. (If the trip were presented exclusively for campaign purposes, the opposition party, government watchdog groups, and others would be crying foul and demanding reimbursement of taxpayer funds.)
For a more detailed analysis of these Presidential trips (along with examples), see this article:
Below are a few excerpts from the article (posted for readers outside the US who cannot access the Chicago Tribune website).
Trump's travel expenses test boundaries of policy and
politics
President Donald Trump has reveled in smashing political precedent,
but on Thursday he followed his White House predecessors in one of
Washington's usually unspoken traditions: blurring the lines between a
campaign trip and official business.
Jetting aboard Air Force One for a quick day trip to western
Pennsylvania, Trump delivered a 25-minute speech at a heavy equipment
manufacturing company. Though aides touted the visit to the facility
in Coraopolis as a chance for Trump to promote his legislative agenda,
an ulterior motive was not so thoroughly disguised.
"Will be going to Pennsylvania today to give my total support to RICK
SACCONE," Trump wrote in a morning tweet. He was referring to the GOP
candidate in a closely contested congressional special election in the
district where the president was headed. "Great guy," Trump declared.
Reporters quickly noted the discrepancy, prompting Trump's press
secretary to issue a statement reiterating that the trip was, in fact,
official business. But by then, Trump had given voice to a reality of
the modern presidency - mixing politics and policy comes with the job.
...
Presidents stretching back to at least Ronald Reagan have unabashedly
doubled up on their to-do list while planning presidential travel,
especially in election years, giving policy speeches by day and
attending fundraisers at night.
Government watchdogs have raised red flags over such dual-purpose
jaunts and who pays for them.
...