# GTM参数未被保存或传递给GTM

**URL:** https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240
**Category:** Support
**Created:** [2024 年5 月 8 日 11:44 UTC](https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240 "2024-05-08T11:44:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### 作者： ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### 发布日期： [2024 年5 月 8 日 11:44 UTC](https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240/1 "2024-05-08T11:44:17Z")

</div>

在稳定版中，当 Ember 重写 URL 时，它会移除任何“未知”的查询参数，例如 `gtm_source`，以便在它们传递给 Google Tag Manager 等工具之前就被移除。

是否有现有的解决方案？

---

<div class="post-metadata">

### 作者： ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### 发布日期： [2024 年5 月 9 日 17:45 UTC](https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240/2 "2024-05-09T17:45:56Z")

</div>

这里有一个解决方法，但肯定不是理想的：

> [@david](#):
>
> 这两种问题的解决方法是创建一个指向外部网站的链接，该网站随后会重定向回您的论坛。（例如 URL 缩短服务）

我在 Ember 论坛上就此问题开了一个帖子，但似乎没有干净的方法可以允许所有参数：

> **[Preserving non-Ember-app query parameters when navigating within App](https://discuss.emberjs.com/t/preserving-non-ember-app-query-parameters-when-navigating-within-app/20454?u=davidtaylorhq)**
>
> When transitioning using routerService.transitionTo("/home?a=b"), or via

那里建议的解决方法如果事先知道参数名称，_可能_会起作用。

尝试一个主题组件可能会很有趣，该组件接受查询参数名称列表（例如 `gtm_source`），并修改 `controller:application` 以包含它们。 🤔

---

<div class="post-metadata">

### 作者： ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### 发布日期： [2024 年5 月 9 日 18:52 UTC](https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240/3 "2024-05-09T18:52:02Z")

</div>

嗯，不，那是不同的东西。

我刚发现这是 `stable` 上的一个问题，  
我还发现（在 stable 上）_某些_ 参数被保留了，比如 `pp`、`safe_mode` 等。但我找不到这些参数的定义位置或如何添加它们。

在 tests-passed 上，所有查询参数都保留了，所以总结一下：

- 如果我访问 [https://stable.example.com/?pp=1&utm\_source=foo，路由器会将其重写为](https://stable.example.com/?pp=1&utm_source=foo%EF%BC%8C%E8%B7%AF%E7%94%B1%E5%99%A8%E4%BC%9A%E5%B0%86%E5%85%B6%E9%87%8D%E5%86%99%E4%B8%BA) [https://stable.example.com/?pp=1（因为](https://stable.example.com/?pp=1%EF%BC%88%E5%9B%A0%E4%B8%BA) `pp` 显然是白名单中的）
- 如果我访问 [https://testspassed.example.com/?pp=1&utm\_source=foo，两个参数都会保留。](https://testspassed.example.com/?pp=1&utm_source=foo%EF%BC%8C%E4%B8%A4%E4%B8%AA%E5%8F%82%E6%95%B0%E9%83%BD%E4%BC%9A%E4%BF%9D%E7%95%99%E3%80%82)

……然后我发现了[这个](https://github.com/discourse/discourse/commit/4f75cee6d2e1184159c0c13983e26fe357d0d2f4)修复。

有没有可能将其反向移植到 stable？看起来它没有任何依赖项，所以应该是安全的。

---

<div class="post-metadata">

### 作者： ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### 发布日期： [2024 年5 月 9 日 21:52 UTC](https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240/4 "2024-05-09T21:52:37Z")

</div>

啊，我明白了。我当时想到的是网站内的链接，这些链接会受到 ember 限制的影响。但你说的是你一登陆网站，查询参数就被重写了 👌

> [@RGJ](#):
>
> 有没有可能将其向后移植到稳定版？

当然，我们来做吧 👍

> <https://github.com/discourse/discourse/pull/26960>
>
> Seems like an accident that the homepage route will always strip all query param…s from the URL.. This fixes that :)
> 
> Backport of 4f75cee6d2e1184159c0c13983e26fe357d0d2f4

---

<div class="post-metadata">

### 作者： ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### 发布日期： [2024 年6 月 8 日 21:52 UTC](https://meta.discourse.org/t/gtm-parameters-are-not-preserved-or-passed-to-gtm/307240/5 "2024-06-08T21:52:54Z")

</div>

此主题在最后回复后自动关闭，已有 30 天。不再允许回复。
