UTM Parameter Lost on AMP Mobile Redirect
-
Hi,
Can anyone provide a step-by-step fix the loss of UTM parameters when the AMP mobile redirect is enabled.
Frustrating as GA is showing everything coming from Social Sources that are mobile as direct.
Appreciate the help!
-
This topic was modified 5 years, 3 months ago by
nteg.
-
This topic was modified 5 years, 3 months ago by
-
Please provide an example URL with UTM parameters that shows this issue.
@westonruter from a mobile the
URL: https://cakelovesme.com/lemon-loaf-cake-recipe-easy?utm_source=facebook&utm_campaign=fb_ad
The AMP Plugin Mobile redirect redirects this to https://cakelovesme.com/lemon-loaf-cake-recipe-easy/?amp=1
This redirect then does not allow GA to pickup that this traffic is coming from a Social source, and shows up as Direct.
Thanks for the help.
I’m not able to reproduce the issue myself but I do see it happening on your site.
I can see in the source code of the non-AMP page the AMP URL is encoded as:
"ampUrl":"https:\/\/cakelovesme.com\/lemon-loaf-cake-recipe-easy\/?amp=1"So indeed it is missing the parameters.
This URL is constructed using this code: https://github.com/ampproject/amp-wp/blob/2.0.10/src/MobileRedirection.php#L85-L94
$url = add_query_arg( amp_get_slug(), '1', amp_get_current_url() ); $url = remove_query_arg( QueryVar::NOAMP, $url );It seems that
amp_get_current_url()is not returning any of the UTM query parameters. Perhaps you have another plugin which is removing those from the$_SERVER['REQUEST_URI']?If this is normal practice for UTM parameters to be stripped out in this way, we may need to update the mobile redirection logic to grab the parameters from the
locationin JS. Nevertheless, server-side redirection may still strip them out in that case.Thanks Weston for looking into this. I have tried deactivating plugins and caches but still no luck on trying to track down why this is happening.
Are you using a CDN or some external cache layer (e.g. Varnish)? It could be that those parameters are stripped out so they are never even seen by your server.
Hi Weston, tried again and did the folowing:
1) disabled varnish
2) disabled redis
3) disabled CDN
4) disabled WPRocket
5) disabled any other plugin exept the WP Theme AstraThen tried—no luck.
did find the following article which sounds similar to the problem, but have not tried the fix shown.
https://github.com/ampproject/amphtml/issues/2685
You thoughts on this fix?
I’m quite confused why this is happening.
I have installed and activated Astra (from ww.wp.xz.cn). I have Transitional mode active with mobile redirection enabled. On a mobile device, when I go to:
/?utm_source=facebook&utm_campaign=fb_adI am redirected to the AMP version via:
/?utm_source=facebook&utm_campaign=fb_ad&=1Regarding the AMP core issue, that doesn’t seem the same as the issue you’re experiencing. Your issue seems to be that the server is stripping out all the UTM query parameters from the request so that PHP doesn’t even see them.
Please share your site health information via our private submission form. Maybe that will help us identify what is going on.
-
This reply was modified 5 years, 3 months ago by
Weston Ruter.
Actually, I think I see the issue. The issue is that your URL lacks the trailing slash:
https://cakelovesme.com/lemon-loaf-cake-recipe-easy?utm_source=facebook&utm_campaign=fb_ad
When that happens, WordPress tries to do a canonical redirect, and the canonical URL lacks the UTM parameters, resulting in a server-side 301 HTTP redirect to:
https://cakelovesme.com/lemon-loaf-cake-recipe-easy/
Then the AMP plugin’s redirection logic is redirecting to the AMP version of this URL that lacks the UTM parameters.
In other words, the mobile redirection is happening after the user has already been redirected by WP. Therefore, the issue is not with the AMP plugin but with WordPress canonical redirects.
You can see that the UTM parameter persist when the trailing slash is included in the URL.
On a mobile device, going to:
https://cakelovesme.com/lemon-loaf-cake-recipe-easy/?utm_source=facebook&utm_campaign=fb_ad
I am redirected as expected to:
https://cakelovesme.com/lemon-loaf-cake-recipe-easy/?utm_source=facebook&utm_campaign=fb_ad&=1
Thanks Weston, much appreciated. This solved the problem with this particular link being tested on Google Browser on mobile. With the trailing slash, in Google on mobile, I am able to see the UTM parameters pass all the way to Google Analytics properly. All good.
Problem I am facing now, is that this exact url being used in a FaceBook Ad is not passing the utm parameters all the way Google Analytics.
Don’t know why, but but for Facebook Mobile users, the utm_source and utm_campaign are never passed on after the FB mobile users click one of my Ads which are directed to this same URL we have been testing, and then redirected to the AMP version of the page.
https://cakelovesme.com/lemon-loaf-cake-recipe-easy/?utm_source=facebook&utm_campaign=fb_ad
Seems that for Facebook Mobile users, the redirection to AMP looses the utm parameters. For Facebook Desktop users who click on the FB Ad with this URL–no problem, the utm_source and utm_campaign can be seen in Google Analytics.
Thanks again for your help. I am going to still try to see why Facebook Mobile users coming from my FB Ads to my site, which are redirected to AMP are unable to pass on the UTM parameters. Currently the Mobile users from FB clicking on an Ad show up as ‘direct’ in GA even though the UTM parameters are set properly in FB for the Ad (used the same URL as above). Interestingly, I tested this URL on a FB Post, and as an FB Mobile user clicking on a FB Post with this URL the utm parameters pass no problem through the AMP mobile redirection—and subsequently I see them in GA.
Something to do with utm parameters and FB Ads, as it passes through an AMP mobile redirect.
Thinking it might have something to do with the new fbclid query parameter that Facebook has been added to its Ads. These fbclid can be quite long, so don’t know if the AMP Mobile redirect is having an issue with these.
On a mobile device, if I go to this URL with a very long
fbclidparameter:I am redirected to the AMP version without any issue and the parameters are retained:
Thanks Weston.
I think at this point it is clear, that something Facebook Mobile app is doing on Ads, failing to pass the appropriate UTM parameters. The Posts in FB work fine, and the tests outside of FB Mobile works fine. It is simply Facebook Mobile ad as one clicks on the Ad on the Facebeook Mobile App that does not pass the UTM parameters on an AMP redirection.
This in a nutshell is the issue, and will have to try to find out from FB what is different about how FB Mobile app and one clicking on their Ads–which has the UTM paraemeters, does not seem to make it through the AMP mobile redirection.
One option would be to try switching from client-side to server-side redirection, using an extension plugin like this: https://gist.github.com/westonruter/e5032d805625f0f743237708c43d3783
It would be preferable to figure out what is going wrong with client-side redirection, but this is an option if your caching layers don’t conflict with server-side redirection.
-
This reply was modified 5 years, 3 months ago by
The topic ‘UTM Parameter Lost on AMP Mobile Redirect’ is closed to new replies.