简体   繁体   English

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

[英]Google Tag Manager (GTM) and Google Analytics variables

Is it possible to get a tag fired by a javascript rule, when the value the rule based on is inside the _gaq javascript? 当基于规则的值在_gaq javascript中时,是否可以获取由javascript规则触发的标记?

This is my Google Analytics 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>

The Google Tag Manager help says this: Google跟踪代码管理器帮助说:

JavaScript Variable: The value is set to that of the global variable you specify. JavaScript变量:该值设置为您指定的全局变量的值。 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. 如果您要查找的值未在数据层中设置(请参阅下面的数据层宏类型),并且它在DOM中不可见(请参阅下面的DOM宏类型),则可能会检索到该值来自JavaScript变量。 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. 如果您可以以JavaScript变量的形式在页面源中找到要查找的值,请使用此宏类型。

Now I want to have a macro for the _trackPageview and a rule for the /ContactFormSent.html based on this macro. 现在我想要_trackPageview的宏和基于此宏的/ContactFormSent.html的规则。 So the variable should be global --> is this the case with '_trackPageview' ? 所以变量应该是全局的 - >这是'_trackPageview'的情况吗? If it is, it should be possible to fire the tag based on this rule. 如果是,则应该可以根据此规则触发标记。

Or is something with the setup inside of the Google Tag Manager wrong? 或者谷歌标记管理器内部的设置是错误的?

  • macroname: trackPageview macroname:trackPageview
  • macrotype: JavaScript-variable macrotype:JavaScript变量
  • name of the global variable: _trackPageview 全局变量的名称:_trackPageview

Thx for helping me out :-) Fabian 谢谢我帮助我:-) Fabian

It's possible to use _gaq, only it's a lot less convenient than you seem to think. 可以使用_gaq,只是它比你想象的要方便得多。 _gaq is an array and every item added via the push-method in the GA code is an array as well. _gaq是一个数组,通过GA代码中的push方法添加的每个项目也是一个数组。 So the way to adress _trackPageview in your example would be _gaq[2][0] (first item in the third array) - at least until somebody adds another "push" to the GA code in which case your GTM rules will break. 因此,在您的示例中添加_trackPageview的方式是_gaq [2] [0](第三个数组中的第一项) - 至少在有人为GA代码添加另一个“推送”之前,在这种情况下您的GTM规则将会中断。 So possible, yes, good idea, not so much. 可能,是的,好主意,而不是那么多。

(To clarify a little more, your error was to think that _gaq is a one-dimensonal array with key=>value pairs. It isn't). (为了澄清一点,你的错误是认为_gaq是一个带有key => value对的一维数组。它不是)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM