It seems there is no clear way to do this. I checked couple of big websites using utm_campain
and it stays after clicking the link, so even big websites consider this as fine.
But if one really wants to remove it, it can be done manually. Assuming that you have canonical address (which you should have if you care about SEO), see some PHP-pseudocode:
function cleanupUtm($currentCanonicalUrl)
{
$currentUrl = $_SERVER['REQUEST_URI'];
// Check are there "utm_" parameters in current URL
if (strpos($currentUrl, 'utm_') === false) {
return;
}
redirect($currentCanonicalUrl);
}
function redirect($location)
{
// Some helper redirect function, see https://stackoverflow.com/a/768472/1657819
header("Location: " . $location);
die();
}
But obviously it will trigger extra redirect and page reload.
Alternative
As an alternative, you may consider using Google Tag Manager
to replace long boring URL with campaign to some neat URL like https://example.com/#instagram
. See for example this article
While it looks neat (and much better than long utm...
string), I feel that it gives you less flexibility (or you will end up with hundreds of tags for all the cases you need)