How to Keep UTM Tags Through a Redirect
You share yoursite.com/go/course/?utm_source=newsletter in an email, and the landing page’s analytics report the visit as direct traffic. The UTM tags were on the short link, but they never made it past the redirect.
To keep UTM tags through a redirect, the redirect has to copy them from the short link onto the destination URL. GT Link Manager sends only the destination you saved, so a small filter adds the incoming utm_ values before the redirect goes out.
GT Link Manager has a filter called gtlm_redirect_url for exactly this kind of change. It runs on every redirect, after country rules have picked the destination, so the tags survive geo links too.
Before you add it, it helps to know when forwarding is worth it.
When Forwarding Helps
UTM tags only matter if the destination reads them. These cases benefit:
- Short links to your own pages, such as a course page, a sales page or a webinar sign-up on another domain you own.
- Partner pages that run GA4 or similar analytics, when the partner asked you to tag your traffic.
- Shared links in newsletters, social posts and ads, where you want each channel credited.
Amazon and most affiliate networks ignore UTM tags. They track your click through their own tag in the destination URL, so forwarding adds nothing there.
Before You Start
- File access to your site, to add a file to
wp-content/mu-plugins. - A branded link to test with, pointing at a page whose analytics you can see.
Add the Forwarding Filter
- Create the folder
wp-content/mu-pluginsif it doesn’t exist. - Create a file in it named
gtlm-utm.php. - Paste the code below and save. There’s nothing to activate.
<?php
/**
* Plugin Name: GT Link Manager UTM Forwarding
* Description: Copies utm_ parameters from a short link onto its destination.
*/
defined( 'ABSPATH' ) || exit;
add_filter( 'gtlm_redirect_url', function ( $url ) {
$keys = array( 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_id' );
$add = array();
foreach ( $keys as $key ) {
if ( isset( $_GET[ $key ] ) && is_string( $_GET[ $key ] ) && '' !== $_GET[ $key ] ) {
$add[ $key ] = rawurlencode( sanitize_text_field( wp_unslash( $_GET[ $key ] ) ) );
}
}
return $add ? add_query_arg( $add, $url ) : $url;
}, 20 );
Three choices in this code are deliberate:
- Only
utm_tags pass through. Other query parameters on the short link stay behind, so nobody can bolt arbitrary parameters onto your affiliate destination. - Incoming tags win. If the destination already has
utm_source=site, a click on?utm_source=newsletterreplaces it. The campaign that brought the click gets the credit. - Priority 20. Other snippets on the same filter, such as the role redirect in How to Show Different Links to Members and Visitors, run at 10 and may swap the whole URL. Running this one later adds the tags to whatever URL they chose.
To also forward ad click IDs, add gclid, fbclid or msclkid to the $keys list.
Count Campaigns in GT Link Manager
Forwarding gives the destination the tags. If you also want campaign numbers inside WordPress, GT Link Manager’s own analytics can match them:
- Go to GT Links → Analytics → Settings and turn on Enable advanced analytics if it’s off.
- Under Campaign tracking, click Add campaign.
- Fill in the Source, Medium and Campaign columns exactly as they appear in your links, such as
newsletter,emailandoctober-launch. - Save the settings.
Clicks whose tags match all 3 values show in the Campaigns tab of the analytics overview. A blank field means that tag must be absent from the link. The match is exact, including capital letters, so Newsletter won’t match a link tagged newsletter.
Values can use letters, numbers, dots, hyphens and underscores, up to 64 characters each. You can have up to 100 campaigns, and removed campaigns still count toward that limit.
This matching reads the tags but never forwards them, so you need the filter above for the destination to see them.
Check It Works
Run curl -I on a branded link with tags:
curl -I "https://yoursite.com/go/course/?utm_source=newsletter&utm_medium=email&utm_campaign=october-launch"
The Location header should end with the same 3 tags. Without the filter, it shows the bare destination.
Then click the tagged link in a private window and check the destination’s real-time report. The visit should show newsletter as its source.
When Tags Still Go Missing
| Symptom | Likely cause | Fix |
|---|---|---|
Location shows no tags | The file isn’t loading | Check it’s directly inside wp-content/mu-plugins, not a subfolder |
| Tags vanish only for logged-in users | Another snippet replaces the URL after this one | Raise this filter’s priority above that snippet’s |
| Tags reach the destination but analytics ignore them | The destination redirects again and drops them | Point the link at the final URL, not one that redirects |
A tag with spaces arrives as + or %20 | Normal URL encoding | Use hyphens in your tag values |
What It Won’t Do
- It doesn’t add tags you didn’t send. The short link has to carry them. A bare
/go/course/forwards nothing. - It doesn’t fix tracking on the destination. If that page has no analytics, the tags sit in the address bar unused.
- It can’t help with affiliate tracking. Stores credit you through their own tag, not UTMs.
The UTM Parameter Passthrough in GT Link Manager reference has a longer version with ad click IDs and a filterable parameter list. Register it at priority 20 too when other snippets share the filter.