首页 文章

在Google Analytics出站链接跟踪中没有'label'

提问于
浏览
0

我已设置Google Analytics事件来跟踪出站链接 . 我跟着the tutorial on Google's site .

我遇到的问题是Google Analytics中没有跟踪“url”参数(事件标签) . 'outbound'和'click'都可以通过ga()调用正常工作 . 如果我在ga()调用之前警告()行上的'url'变量,它将成功提醒屏幕 .

为什么Category(出站)和Action(click)工作得很好 . 但是,标签(var url)没有显示在Google Analytics中?

jQuery(document).ready(function() {
    initExternalLinkLogging();
});

function initExternalLinkLogging() {
    // ':external' is from here and works great: http://stackoverflow.com/questions/1227631/using-jquery-to-check-if-a-link-is-internal-or-external
    externalLinks = jQuery("a:external");
    jQuery(externalLinks).click(function() {
        trackOutboundLink(this);
    });
}

function trackOutboundLink(url) {
    // This is the triggered on each outbound link click successfully
    // 'url' has the correct value, but is not showing up in Google Analytics
    try {
        ga('send', 'event', 'outbound', 'click', url, {
            'hitCallback': function() {
                document.location = url;
            }
        });
    } catch (err) {
        // Do nothing for now
    }
}

1 回答

  • 0

    我已经解决了这个问题 . 在此上下文中,'url'变量是一个对象,即使屏幕上的警报将其显示为URL的字符串 . 只需更改此函数调用即可解决问题 .

    //This doesn't work
    trackOutboundLink(this);
    
    //This fixes it. See ".href"
    trackOutboundLink(this.href);
    

    因此,在工作状态下引用的完整代码是:

    jQuery(document).ready(function() {
        initExternalLinkLogging();
    });
    
    function initExternalLinkLogging() {
        // ':external' is from here and works great: http://stackoverflow.com/questions/1227631/using-jquery-to-check-if-a-link-is-internal-or-external
        externalLinks = jQuery("a:external");
        jQuery(externalLinks).click(function() {
            trackOutboundLink(this);
        });
    }
    
    function trackOutboundLink(url) {
        // This is the triggered on each outbound link click successfully
        // 'url' has the correct value, but is not showing up in Google Analytics
        try {
            ga('send', 'event', 'outbound', 'click', url, {'hitCallback':
                    function() {
                        document.location = url;
                    }
            });
        } catch (err) {
        }
    }
    

相关问题