GTM parameters are not preserved, or passed to GTM

AI-generated summary

The discussion revolves around GTM parameters not being preserved or passed to GTM due to Ember rewriting the URL on Discourse’s stable version. RGJ found that only some parameters, like pp and safe_mode, are kept, while others are removed. RGJ discovered a fix that was committed to the tests-passed branch and requested it to be backported to stable.

david initially suggested a workaround involving an external redirect, but later understood the issue was with query parameters being rewritten upon landing on the site. david agreed to backport the fix to stable, creating a pull request (https://github.com/discourse/discourse/pull/26960).

On stable, when Ember is rewriting the URL, it removes any “unknown” query parameters, including things like gtm_source, before they can be passed to for instance Google Tag Manager.

Is there any existing solution for this?

There is a workaround here, but it’s definitely not ideal:

I opened a topic on the Ember forum about it, but it doesn’t seem like there is any clean way to allow all params:

The workaround suggested there could potentially work if you know the parameter names up-front.

It could be interesting to experiment with a theme component which takes a list of query param names (e.g. gtm_source), and modifies controller:application to include them. :thinking:

Hmm, no, that’s something different.

I just found out this is an issue on stable only,
what I also found is that (on stable) some parameters are being kept, like pp, safe_mode and such. But I can’t find where these are defined or how to add to them.

On tests-passed all query parameters stay, so to summarize:

…and then I found this fix.

Is there any chance of it being backported to stable? Seems it does not have any dependencies so it should be safe.

Ahh I see. I was thinking of links within the site, which are affected by that ember limitation. But you’re talking about query params being rewritten as soon as you land on the site :ok_hand:

Sure, let’s do it :+1:

https://github.com/discourse/discourse/pull/26960