根据特定历史记录更改触发 GTM dataayer 变量

发布于 2025-01-18 18:32:44 字数 494 浏览 1 评论 0 原文

我正在使用 react-gtm-module 我项目的经理。截至目前,我在以下代码要求的情况下触发数据层变量

 window.dataLayer = window.dataLayer || []
          window.dataLayer.push({
          Car_NewUser_Create: 'Yes'
 })

,但是现在有一个特殊情况,当我们从“/simulcao”路由“/pactotes”路线时,我需要发射相同的可变“ car_newuser_create”。

GTM中有一种用于历史记录变化的配置,可以检测到历史路线的每一个变化,但是对于此特定的路线更改,我需要传递此变量,我找不到有关如何实现它的任何来源。

谢谢 !

I am using react-gtm-module in my react project to add Google Tag Manager in my project. As of now i was firing the dataLayer variable whereever required by the following code

 window.dataLayer = window.dataLayer || []
          window.dataLayer.push({
          Car_NewUser_Create: 'Yes'
 })

but now there is a special case where i need to fire this same varaible "Car_NewUser_Create" when we go from "/simulcao" route to "/pacotes" route.

There is a configuration in GTM for history triger change that detects every change in history route, but for this specfic route change i need to pass this variable and I am not able to find any source on how to achieve it.

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何时共饮酒 2025-01-25 18:32:44

您可以使用历史更改事件中填充的两个未记录的变量,即 gtm.oldUrlgtm.newUrl

这是启用并触发历史更改事件时 GTM 将推送到数据层的示例:

dataLayer.push({
  event: "gtm.historyChange",
  gtm.historyChangeSource: "pushState",
  gtm.oldUrlFragment: "",
  gtm.newUrlFragment: "",
  gtm.oldHistoryState: "",
  gtm.newHistoryState: {key: "", state: ""},
  gtm.oldUrl: "https://example.com/old-url",
  gtm.newUrl: "https://example.com/new-url",
  gtm.uniqueEventId: 0000
})

由于某些原因,变量在 变量文档并且不可用作为要启用的内置变量。

只需配置两个新的 dataLayer 变量即可捕获它们。一旦解决了这个问题,您就可以在 GTM 中应用的任何逻辑中使用它们。

在您的情况下,为 dataLayer.push({ Car_NewUser_Create: 'Yes' }) 设置一个标记,其中包含 Some History Changes 的历史记录更改触发器,并具有两个规则:

  1. gtm.oldUrl 等于 https://example.com/old-url
  2. gtm.newUrl 等于 https://example.com/new -url

这是一个示例

You can use two undocumented variables populated on a history change event, i.e., gtm.oldUrl and gtm.newUrl.

This is an example of what GTM will push to the dataLayer when the history change event is enabled and triggered:

dataLayer.push({
  event: "gtm.historyChange",
  gtm.historyChangeSource: "pushState",
  gtm.oldUrlFragment: "",
  gtm.newUrlFragment: "",
  gtm.oldHistoryState: "",
  gtm.newHistoryState: {key: "", state: ""},
  gtm.oldUrl: "https://example.com/old-url",
  gtm.newUrl: "https://example.com/new-url",
  gtm.uniqueEventId: 0000
})

For some reason, the variables are undocumented in the variable docs and unavailable as built-in variables to be enabled.

Simply configure two new dataLayer variables to capture them. Once that's out of the way, you can use them in any logic you need to apply in GTM.

In your case, set up a tag to dataLayer.push({ Car_NewUser_Create: 'Yes' }) with a history change trigger for Some History Changes with two rules:

  1. gtm.oldUrl equals https://example.com/old-url
  2. gtm.newUrl equals https://example.com/new-url

Here's an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文