I'm using Google Tag Manager with a Rails 4.2 app with turbolinks. I'm completely stumped and am completely unable to use Google Tag Manager effectively with turbolinks.
我正在使用带有turbolinks的Rails 4.2应用程序的Google跟踪代码管理器。我完全被难倒了,完全无法使用turbolinks有效地使用Google跟踪代码管理器。
Google tag manager seems to repeatedly sense new page loads (the <body>
tag getting replaced) as new installations of google tag manager. When I look at my Google tag assistant recordings I just see an endless sea of Green Tags for Google Tag Manager.
谷歌标签管理器似乎反复感知新页面加载(标签被替换)作为谷歌标签管理器的新安装。当我查看我的Google标签助理录音时,我只看到Google Tag Manager的绿色标签。
Anyone have any leads on resources where I can figure out how to use it effectively?
任何人都有资源上的任何线索,我可以弄清楚如何有效地使用它?
I've looked at Googletagmanager with Turbolinks which seems to be slightly dated, but also doesn't solve my problem of errant installations.
我看过带有Turbolinks的Googletagmanager,这似乎有些过时,但也没有解决我的错误安装问题。
1 个解决方案
#1
-1
Replacing the tag will may all kinds of side effects (as you now realize, one being that the code is re-initialized and fires gtm.js events), so I suggest you drop the noscript part and move the rest to the head - I don't really know turbolinks (or RoR), but according to this article turbolinks will not reload the head.
替换标签可能会产生各种副作用(正如您现在意识到的那样,一个是代码被重新初始化并触发gtm.js事件),所以我建议您删除noscript部分并将其余部分移到头部 - 我我真的不知道turbolinks(或RoR),但根据这篇文章,turbolinks不会重新加载头部。
Unfortunately there still might be side effects in an SPA since all items pushed to the dataLayer will just stay there. You might want to consider reseting the dataLayer when you load new content:
不幸的是,SPA中可能还有副作用,因为推送到dataLayer的所有项目都会停留在那里。您可能需要考虑在加载新内容时重置dataLayer:
window.google_tag_manager[{{Container ID}}].dataLayer.reset();
Where {{Container ID}} is (obviously) the GTM-XXX id for your container. Don't just over the dataLayer variable with an uninitialized array (dataLayer = []) since GTM adds some methods to the dataLayer variable that will get lost if you overwrite it, and your GTM instance will stop to work.
其中{{Container ID}}(显然)是您容器的GTM-XXX ID。不要只使用未初始化的数组(dataLayer = [])覆盖dataLayer变量,因为GTM会向dataLayer变量添加一些方法,如果覆盖它们将会丢失,并且您的GTM实例将停止工作。
#1
-1
Replacing the tag will may all kinds of side effects (as you now realize, one being that the code is re-initialized and fires gtm.js events), so I suggest you drop the noscript part and move the rest to the head - I don't really know turbolinks (or RoR), but according to this article turbolinks will not reload the head.
替换标签可能会产生各种副作用(正如您现在意识到的那样,一个是代码被重新初始化并触发gtm.js事件),所以我建议您删除noscript部分并将其余部分移到头部 - 我我真的不知道turbolinks(或RoR),但根据这篇文章,turbolinks不会重新加载头部。
Unfortunately there still might be side effects in an SPA since all items pushed to the dataLayer will just stay there. You might want to consider reseting the dataLayer when you load new content:
不幸的是,SPA中可能还有副作用,因为推送到dataLayer的所有项目都会停留在那里。您可能需要考虑在加载新内容时重置dataLayer:
window.google_tag_manager[{{Container ID}}].dataLayer.reset();
Where {{Container ID}} is (obviously) the GTM-XXX id for your container. Don't just over the dataLayer variable with an uninitialized array (dataLayer = []) since GTM adds some methods to the dataLayer variable that will get lost if you overwrite it, and your GTM instance will stop to work.
其中{{Container ID}}(显然)是您容器的GTM-XXX ID。不要只使用未初始化的数组(dataLayer = [])覆盖dataLayer变量,因为GTM会向dataLayer变量添加一些方法,如果覆盖它们将会丢失,并且您的GTM实例将停止工作。