Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google analytics没有调用uu utm.gif,但不会抛出任何错误消息_Javascript_Google Analytics - Fatal编程技术网

Javascript Google analytics没有调用uu utm.gif,但不会抛出任何错误消息

Javascript Google analytics没有调用uu utm.gif,但不会抛出任何错误消息,javascript,google-analytics,Javascript,Google Analytics,我对谷歌分析有问题。我知道有很多问题,但找不到解决办法 我想在Google analytics中将用户的电子邮件地址记录为自定义变量。我在一个函数中有谷歌分析片段,并传入用户电子邮件地址 GA插件不会向控制台窗口输出任何内容 没有javascript错误 我用断点逐步完成了代码,下面的函数一直运行到完成。它进入if语句等 文件ga.js加载成功,但未调用_utm.gif文件 <script type="text/javascript"> //<![CDATA[

我对谷歌分析有问题。我知道有很多问题,但找不到解决办法

我想在Google analytics中将用户的电子邮件地址记录为自定义变量。我在一个函数中有谷歌分析片段,并传入用户电子邮件地址

GA插件不会向控制台窗口输出任何内容

没有javascript错误

我用断点逐步完成了代码,下面的函数一直运行到完成。它进入if语句等

文件ga.js加载成功,但未调用_utm.gif文件

    <script type="text/javascript">
    //<![CDATA[        
    function googleTrack(email) {
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'xyz']);
        _gaq.push(['_trackPageview']);

        if ((parent == null) || (!parent.IsCMSDesk)) {
            //track user name
            _gaq.push(['_setCustomVar', //1, \"Email address\", \"{0}\", 3)
                1,                   // This custom var is set to slot #1.  Required parameter.
                'email_address',     // The name acts as a kind of category for the user activity.  Required parameter.
                email,               // This value of the custom variable.  Required parameter.
                3                    // Sets the scope to page-level.  Optional parameter.
                ]);

            //if googleCustomVar is defined, it will track it. if not, won't
            if (!((typeof (window.googleCustomVar) === "undefined") && (typeof (googleCustomVar) === "undefined"))) {
                _gaq.push(['_setCustomVar', //1, \"Email address\", \"{0}\", 3)
                2,                   // This custom var is set to slot #1.  Required parameter.
                'section',     // The name acts as a kind of category for the user activity.  Required parameter.
                googleCustomVar,               // This value of the custom variable.  Required parameter.
                3                    // Sets the scope to page-level.  Optional parameter.
                ]);
            }
        }

        (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);
        })();
    }

    googleTrack('testm@healthed.com');
    //]]>
</script>

什么东西在这里不起作用?最终目标是能够调用一个函数,该函数将跟踪用户的电子邮件地址作为Google analytics中的一个自定义变量。

您将
\u gaq
定义为函数内部的一个局部变量。因此,谷歌分析代码无法读取该变量。原始代码使用
var
,因为它是在本地范围内执行的。要从函数中声明全局范围内的变量,请省略
var
,或使用
窗口。\u gaq=…

您的坏代码:

<script type="text/javascript">
//<![CDATA[        
function googleTrack(email) {
    var _gaq = _gaq || [];      //<--- `var` inside a function = local variable

谢谢JavaScript语法有一些奇怪的怪癖。我也没有意识到它必须在全球范围内,但这很有道理:)
<script type="text/javascript">
//<![CDATA[        
function googleTrack(email) {
    var _gaq = _gaq || [];      //<--- `var` inside a function = local variable
    _gaq = _gaq || [];