Google Analytics is JavaScript code that runs in your page. To track UTM parameters, the JavaScript looks at the page URL, sees if there are parameters in it, and sends them to to be tracked.
Putting the tracking parameters on a 301 redirect URL won't get them tracked by Google Analytics unless they are passed on to the final URL.
- Tracked:
http://example.com/page?utm_campaign=...
-> https://example.com/page?utm_campaign=...
- NOT tracked:
http://example.com/page?utm_campaign=...
-> https://example.com/page
By default most redirects strip the query string from the redirect URL. mod_alias
under Apache does so. mod_rewrite
also does unless you use the QSA
flag for "query string append". If you implement your redirect with mod_rewrite and want to preserve the query string using the flags [R=301,QSA,L]
as in:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://example.com/$1 [R=301,QSA,L]