javascript - Google 跟踪代码管理器 (GTM) 和 Google Analytics 变量

标签 javascript google-analytics google-tag-manager

当规则所基于的值在 _gaq javascript 内部时,是否有可能让 javascript 规则触发标签?

这是我的 Google Analytics javascript:

<script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-960143-1']);
            _gaq.push(['_setDomainName', '.immoscout24.ch']);
            _gaq.push(['_trackPageview', '/ContactFormSent.html']);
            _gaq.push(['_trackPageLoadTime']);
            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                })();
            </script>

Google 跟踪代码管理器帮助是这样说的:

JavaScript Variable: The value is set to that of the global variable you specify. If the value you're looking for was not set up in the data layer (see Data Layer macro type, below), and it's not visible in the DOM (see DOM macro types, below), it's possible that the value can be retrieved from a JavaScript variable. Use this macro type if you can find the value you're looking for in the source of the page in the form of a JavaScript variable.

现在我想要一个用于 _trackPageview 的宏和一个基于该宏的用于/ContactFormSent.html 的规则。所以变量应该是全局的——> '_trackPageview' 是这种情况吗? 如果是,则应该可以根据此规则触发代码。

或者 Google 跟踪代码管理器内部的设置有问题吗?

  • 宏名:trackPageview
  • 宏类型:JavaScript 变量
  • 全局变量的名称:_trackPageview

谢谢你帮助我 :-) 费边

最佳答案

可以使用 _gaq,只是它没有您想象的那么方便。 _gaq 是一个数组,在 GA 代码中通过推送方法添加的每个项目也是一个数组。因此,在您的示例中处理 _trackPageview 的方法是 _gaq[2][0](第三个数组中的第一项)- 至少直到有人向 GA 代码添加另一个“推送”,在这种情况下,您的 GTM 规则将被破坏。所以可能,是的,好主意,不是那么多。

(为了更清楚一点,您的错误是认为 _gaq 是具有键=>值对的一维数组。它不是)。

关于javascript - Google 跟踪代码管理器 (GTM) 和 Google Analytics 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13160706/

相关文章:

javascript - Function 的 __proto__ 是什么?

javascript - 如何确保 _gaq.push() 正常工作?

javascript - 新手将我的 GA 代码放入他们的网站时出现问题

javascript - dataLayer.push后数据什么时候发送到google

google-analytics - 当输入是 URL 的一部分时,如何在 Google 标记管理器中使用查找表?

javascript - jquery on drop 获取完整路径名

javascript - 在 javascript 中,为什么 null !== undefined 是 true,但是 null == undefined 也是 true?

javascript - 如何在 Jquery 中制作重定向页面?

ios - iOS 上的 Google Analytics(分析)警告

amazon-web-services - ECS服务自动伸缩