Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 trackEvent无法正常工作_Javascript_Jquery_Google Analytics - Fatal编程技术网

Javascript 内部链接的Google Analytics trackEvent无法正常工作

Javascript 内部链接的Google Analytics trackEvent无法正常工作,javascript,jquery,google-analytics,Javascript,Jquery,Google Analytics,我正在使用ga.js。我的代码正在记录一些内部链接,但在我测试的页面上,显示了的内部链接的总事件数为1,而它本应为50。我还查看事件中的实时报告。我所有的外表都会马上出现,但我的内心却不会。我不明白为什么除了内部链接之外,所有的东西都能工作。我的代码如下: <script type="text/javascript"> if (typeof jQuery != 'undefined') { jQuery(docu

我正在使用ga.js。我的代码正在记录一些内部链接,但在我测试的页面上,显示了的内部链接的总事件数为1,而它本应为50。我还查看事件中的实时报告。我所有的外表都会马上出现,但我的内心却不会。我不明白为什么除了内部链接之外,所有的东西都能工作。我的代码如下:

        <script type="text/javascript">
            if (typeof jQuery != 'undefined') {
                jQuery(document).ready(function ($) {
                    var pdffiletype = /\.(pdf)$/i;
                    var filetypes = /\.(zip|exe|doc*|xls*|ppt*|mp3)$/i;
                    var baseHref = '';
                    if (jQuery('base').attr('href') != undefined)
                        baseHref = jQuery('base').attr('href');
                    jQuery('a').each(function () {
                        var href = jQuery(this).attr('href');
                        if (href && (href.match(/^https?\:/i)) && (!href.match(document.domain))) {
                            jQuery(this).click(function () {
                                var extLink = href.replace(/^https?\:\/\//i, '');
                                _gaq.push(['_trackEvent', 'External', 'Click', extLink]);
                                if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
                                    setTimeout(function () { location.href = href; }, 200);
                                    return false;
                                }
                            });
                        }
                        else if (href && href.match(/^javascript\:/i)) {
                            //do not track
                            return true;
                        }
                        else if (href && href.match(/^mailto\:/i)) {
                            jQuery(this).click(function () {
                                var mailLink = href.replace(/^mailto\:/i, '');
                                _gaq.push(['_trackEvent', 'Email', 'Click', mailLink]);
                            });
                        }
                        else if (href && href.match(pdffiletype)) {
                            jQuery(this).click(function () {
                                var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                                var filePath = href;
                                _gaq.push(['_trackEvent', 'PDF', 'Click', $(this).html(), 0]);
                                if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
                                    setTimeout(function () { location.href = baseHref + href; }, 200);
                                    return false;
                                }
                            });
                        }
                        else if (href && href.match(filetypes)) {
                            jQuery(this).click(function () {
                                var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                                var filePath = href;
                                _gaq.push(['_trackEvent', 'Download', 'Click-' + extension, filePath]);
                                if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
                                    setTimeout(function () { location.href = baseHref + href; }, 200);
                                    return false;
                                }
                            });
                        }
                        else if (href) {
                            //assume internal link

                            _gaq.push(['_trackEvent', 'Internal', 'Click', href]);
                        }

                    });
                });
            }
        </script>

只需更改此对齐方式:_gaq.push[''u trackEvent','Download','Click-'+扩展名,filePath];到 ga“发送”、“事件”、“下载”、“单击”文件路径; 它又为我工作了