
2020年8月25日
如果Google跟踪代码管理器中的事件跟踪不起作用怎么办?
更新时间:2020年8月25日。
利用Google跟踪代码管理器,您可以跟踪网站上的各种事件,然后将数据发送到可以分析的工具(如Google Analytics(分析))。在许多标准情况下,无需开发人员就可以跟踪这些事件’的输入。但是,有时您可能在事件跟踪不起作用时陷入困境。
在尝试帮助时 我课程的学生和读者,我’我注意到一些比其他问题更普遍的问题。因为我一直主张 大规模帮助,编写像这样的故障排除指南绝对可以帮助您。
在今天’s blog post, we’ll take a look at the most common issues why your 事件 tracking in Google Tag Manager is not working.
顺便说一句,如果这些技巧都不适合您,请在评论中告诉我。尽可能详细地描述您的问题(带有屏幕截图的链接),我’请尝试提供帮助(并相应地更新博客文章)。

目录
- #1数据层损坏
- #2。你避风港’t created a trigger
- #3。使用错误的触发器
- #4。处理iFrame?
- #5。尝试使用内置的表单提交触发器?
- #6. dataLayer.push does not include the 事件 key
- #7。错别字(+区分大小写)
- #8。 YouTube触发器不起作用?
- #9。标签正在触发,但是您可以’t 看到 the data in GA Realtime reports?
- #10。唐’别忘了发布您的容器
- #11。劫持的ga()方法
- Google跟踪代码管理器中的事件跟踪仍然不起作用吗?
#1数据层损坏
Google跟踪代码管理器中的事件跟踪依赖于 资料层。但是,您站点上的粗心配置可能会破坏它。
您如何知道网站上的数据层是否损坏?启用 预览和调试模式Â and then check what 事件s are displayed on the left side of the debug console.
Normally, you ALWAYS must 看到 AT LEAST 3 事件s in the preview mode:
If, on the other hand, you 看到 just the DOM准备就绪 and 视窗已载入, and instead of the 页面预览 you 看到 a mysterious 信息, 你有问题。
If this is exactly what you 看到, 阅读本指南,了解如何修复数据层.
#2。你避风港’t created a trigger
这适用于您尝试在GTM中使用内置触发器的情况,例如 只是链接, 所有元素点击或 表格提交 (但不限于)。
Some GTM beginners just enable the related variables (e.g. 请点击 ID, 请点击 Text, etc.) and hope that they will start 看到ing 请点击 事件s in the Preview and debug console. However, that is not enough.
You also need to have enabled a trigger to start 看到ing 事件s in the preview mode (this applies to the built-in 事件 tracking functionality of GTM). So, if we are talking about the link click tracking, you need to complete both steps:
- 启用与点击相关的变量
- 至少有 只是链接 在页面上启用了触发器(任何条件都可以使用)
如果您对“所有点击”感兴趣,则至少启用一次 所有元素点击 触发等
Once you have done that, refresh the preview and debug mode and then interact with the element. Now, you should 看到 that 事件 in the preview console.
#3。使用错误的触发器
Sometimes, you might be using the wrong trigger to track a particular interaction. 这里 are several examples.
#1您正在尝试使用a跟踪元素的点击 只是链接 触发,但该元素没有链接。
您可以检查该元素(右键单击它>检查),然后检查该元素是否被包围 <a>标签。如果不是,则无法使用 只是链接点击 触发。
#2。尝试在非YouTube视频播放器上使用YouTube视频触发
顾名思义,触发器仅支持Youtube视频播放器。如果您要处理Vimeo,通用HTML5播放器等, 阅读本指南.
#4。处理iFrame?
您可能会尝试跟踪iframe中元素的交互。简而言之,iFrame允许在网站上嵌入HTML文档。该文档可以只包含一个按钮,一个视频播放器,一个预订表单,甚至整个网站。
iFrame的内容可以属于您的站点,也可以托管在完全不同的域中。
这里’关于iFrame跟踪的要点:即使您作为网站访问者可以与之交互(单击,滚动等),但父页面(包括GTM)上的JavaScript也无法“see”该iFrame内部发生了什么(除非您有权访问’在该iFrame中)。
这里’s a situation:
- 您正在努力 mywebsite.com
- 并且在您的网站上有一个页面(mywebsite.com/contact),其中包含一个表单(最初托管在 someotherwebsite.com)
- 那 form is embedded in an iFrame
- 您的GTM容器代码段仅在 mywebsite.com 而且iFrame无法为您提供在其中添加一些自定义代码的机会。
If you are dealing with this situation, you are most likely out of luck and will not be able to track 事件s within that iframe (有一些例外)。
另一方面,如果您(或您的开发人员)可以在该iframe中添加一些自定义代码,那么您应该 阅读本指南.
阅读本章后,您的问题可能是:
- 我怎么知道我是否’在处理一个iFrame?
- 我怎么知道是否可以在iFrame中添加代码?
让’s address them both.
#1我怎么知道我是否’在处理一个iFrame? 右键单击要跟踪的元素,然后在 元素 标签,向上爬,直到找到<iframe>
如果找到它,那’一个iframe。如果你没有’t,那么Google跟踪代码管理器中的事件跟踪无法正常工作的原因就在于其他地方。
#2。我怎么知道是否可以在iFrame中添加代码? 几种选择:
- 与您的开发人员交谈并询问是否’s possible
- 如果第三方供应商提供了该嵌入式iframe形式(或其他形式),请与他们的支持人员联系,询问是否可以在其中放置自定义JavaScript代码。如果是的话 继续本文。如果没有,那么您很不走运(如果没有 JavaScript API)。

#5。尝试使用内置的表单提交触发器?
如果您尝试在网站上跟踪表单,并且使用内置的GTM表单提交触发器,则有很多原因导致表单不起作用。 阅读此博客文章我在其中详细解释所有内容(+提供解决方案)
#6. dataLayer.push does not include the 事件 key
如果您想在任意位置触发代码 dataLayer.push,则该推送必须包含一个‘event’ key, for example:
window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'formSubmitted' });
然后,您可以使用 自定义事件触发Â并激活您的标签。另一方面,如果dataLayer.push不包含‘event’, all you will 看到 in the Preview mode is 信息.
即使它向数据层添加了一些数据,您也无法使用 信息 推送作为触发条件。
#7。错别字(+区分大小写)
Google跟踪代码管理器中的许多内容都区分大小写。例如,这意味着 productid≥productID。 Keep that in mind when you create triggers. For example, you 看到 a custom dataLayer.push where the ‘event’ key is ‘formSubmission’:
window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'formSubmitted' });
If you created a custom 事件 trigger like this:
它不起作用(因为您需要使用大写的S)。
另外,请检查错别字。例如,如果您要访问 属性 键入dataLayer(我刚刚完成了该示例),然后确保您没有’t跳过任何字母(并输入类似 属性 (一个“t’)).
#8。 YouTube触发器不起作用?
您是否要衡量嵌入式YouTube视频播放器的参与度,但是’t 看到 any video 事件s in the GTM preview mode? You are not alone. 在 fact, there are many possible reasons why this is not working. I’ve发布了另一本指南 致力于解决这个问题。
#9。标签正在触发,但是您可以’t 看到 the data in GA Realtime reports?
This happens also pretty often. Looking at the GTM preview mode, everything 看到ms to be fine, right? The tag is firing exactly when you expect it to happen. However, when you go to GA >实时,该事件不可见。为什么?
有许多可能的原因(例如GA过滤器,GTM中的某些配置等)。为了帮助您解决此问题, I’ve发表了博客文章 前一段时间。
#10。唐’别忘了发布您的容器
一旦检查了事件是否被正确跟踪,就不要’不要忘记发布GTM容器。当你’re in the preview mode, you will 看到 your data in GA properly. However, the rest of your website traffic is still not being measured.
那’s because other visitors are not 看到ing the preview mode. If you want to make your changes public, you need to publish your GTM container.
To do that, click SUBMIT in the top right corner of your GTM interface and follow all the necessary steps. After you do that, you will start 看到ing 事件s coming in from all the visitors of your website.
#11。劫持的ga()方法
这个技巧来自 西莫·阿哈瓦(Simo Ahava)’s blog.
即使您的代码已触发,也请仔细查看预览和调试模式。如果您希望代码在网页上触发“Scroll Depth”事件,请在预览模式下单击该事件,然后检查标记的状态。是吗“Still running”?
如果是,则表示未发送到Google Analytics(分析)的请求。有三个可能的原因:
- 您将GA设置变量插入了错误的字段(您可以 在此处阅读提示#1)
- ga()方法被劫持
- 网站上不存在不存在的Google Optimize容器(您可以阅读有关它的内容) 在Simo’s guide)
我将重点讨论第二个原因。
其他代码/工具可能会覆盖Google Analytics(分析)使用的全局ga()方法。这意味着GA设置刚刚中断,无法发送任何匹配。
让’检查您是否遇到这种情况。在浏览器中打开JavaScript控制台,然后输入以下命令:
console.log(window[window['GoogleAnalyticsObject']].answer);
如果返回42,则说明您’很好,问题出在其他地方。
如果未返回42,但返回其他值(很可能是 未定义),您的ga()方法已被劫持。
如何解决?您可以在GTM中定义另一个全局函数名称。必须在所有GA标签中完成此操作,因此请使用 GA设定变数 为了那个原因。
Google跟踪代码管理器中的事件跟踪仍然不起作用吗?
您的事件跟踪无法正常工作还有更多可能的原因,但是,我想指出在帮助学生时遇到的最常见问题。
如果这些提示都没有帮助您,请在评论中告诉我。也许我忘了提些什么,或者您正面临一些我肯定应该列入清单的新案例?
这些技巧很多都是菜鸟的错误。如果您想避免这些问题并通过Google跟踪代码管理器变得更好,请考虑以下下载我的GTM初学者免费电子书。

The variables are not showing in the debug mode, it fires the 事件 but not if i set it for specific class :(
我不确定我是否理解。请解释。
I have a page created in Wordpress. When I search for a plugin to track 事件s, several are displayed.
您能推荐一个具体的吗?
嗨,朱利叶斯。感谢您的文章。我的datalayer变量有一个主要问题。目前我有一个数据层推送
" <script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({'Topic':[{'Digital Design'}]}));
</script>"
我已经创建了一个称为“主题”的DLV,并且每当在调试模式下对其进行检查时,都会得到“未定义”。我该怎么做才能纠正这个问题?
因此,我遇到了相反的问题。使用跟踪代码管理器预览模式时,我可以看到事件触发,它显示在Goggle Analytics实时窗口中。但是,该实时数据并未保存在“行为> Events >概述”,因此我的事件记录仅存在30分钟(在实时窗口中可见)。
You need to wait for up to 24 hours to 看到 data in Behavior >大事记> Overview
嘿朱利叶斯,
不错的文章,以及本课程的精彩章节。
但是,对于以下挑战,我需要一个主意,也许您有。在你的脑海:
我的一个客户的页面上有几个iframe。它们具有不同的URL,父域上的不同页面也是如此。
您是否认为可能仅将域作为childOrigin / parentOrigin?谢谢你的自发想法。
Events are working in preview but GA dont recieve data of this 事件s