跟踪Google Analytics(分析)中的所有出站链接 [英] Track all outbound links in Google Analytics

查看:129
本文介绍了跟踪Google Analytics(分析)中的所有出站链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月来我一直在使用脚本来跟踪出站链接. 脚本WORKS ,但是在Google Analytics(分析)生成的报告中,许多URL的末尾都有:80"(默认端口号).继续阅读以获取更多详细信息.

I've been using a script to track outbound links for a couple of months now. The script WORKS, but in the report generated by Google Analytics many URLs are having a trailing ":80" (default port number) at their end. Read on for more details.

值得一提的是跟踪这些出站链接的网站有大量出站流量(您的幻想乘以∞).

它会跟踪所有出站链接,并在Google Analytics(分析)中将其标记为出站链接".

该脚本已被大量注释,并具有console.log()的一些实例以帮助调试(这些注释已被注释掉).

The script is heavily commented and has a few instances of console.log() to help debugging (these are kept commented out).

出站链接"在GA上正确显示,位于:

"Outbound Links" show on GA alright, under:

内容>事件>热门事件>出站链接" [单击它]> [报告显示所有被单击的URL]

在出站链接"报告下,我获得了所有单击的链接,在至少报告的所有链接的2/3(可能更多)的末尾,我得到:80". GA对待 http://example.com http://example. com:80 作为不同的链接,在报告中将它们分开. 那当然是不希望的.

Under the "Outbound Links" report, where I get all the links that were clicked, I get ":80" at the end of at least 2/3 of all links reported (probably more). GA treats http://example.com and http://example.com:80 as different links, separating them in the report. That's of course not desired.

值得一提:

Worth mentioning:

以:80"结尾的链接总是比没有:80"的链接具有更高的点击率,点击率增加40%到60%.

Links that end with ":80" always have more hits than their equivalent without ":80", anything from 40% to 60% more hits.

  • 将以:80"结尾的链接与没有链接的链接合并在一起,或者
  • 如果可能,请避免在链接后附加:80".
  • 奖金:理解为什么我们完全获得了以:80"结尾的链接.
// Outbound Link Tracking with Google Analytics
// Requires jQuery 1.7 or higher (use .live if using a lower version)
$(function() {
    $("a").on('click',function(e){
        var url = $(this).attr("href");
        // Console logs shows the domain name of the link being clicked and the current window
        // console.log('e.currentTarget.host: ' + e.currentTarget.host);
        // console.log('window.location.host: ' + window.location.host);
        // If the domains names are different, it assumes it is an external link
        // Be careful with this if you use subdomains
        if (e.currentTarget.host != window.location.host) {
            // console.log('external link click');
            // Outbound link! Fires the Google tracker code.
            _gat._getTrackerByName()._trackEvent("Outbound Links", e.currentTarget.host, url, 0);
            // Checks to see if the ctrl or command key is held down
            // which could indicate the link is being opened in a new tab
            if (e.metaKey || e.ctrlKey) {
                // console.log('ctrl or meta key pressed');
                var newtab = true;
            }
            // If it is not a new tab, we need to delay the loading
            // of the new link for a just a second in order to give the
            // Google track event time to fully fire
            if (!newtab) {
                // console.log('default prevented');
                e.preventDefault();
                // console.log('loading link after brief timeout');
                setTimeout('document.location = "' + url + '"', 100);
            }
        }
        /*
        else {
            console.log('internal link click');
        }
        */
    });
});

推荐答案

在输出中出现:80的原因是由于e.currentTarget.host

The reason for the :80 in your output is because of e.currentTarget.host

http://www.w3schools.com/jsref/prop_area_host.asp

除了可以运行的url变量外,我不确定为什么要跟踪它,但是始终可以通过简单的字符串替换来确保:80不存在

I'm not sure why you are tracking that in addition to your already functional url variable, but you can always insure that :80 is not there with a simple string replace

_gat._getTrackerByName()._trackEvent("Outbound Links", e.currentTarget.host.replace(':80',''), url, 0);

这篇关于跟踪Google Analytics(分析)中的所有出站链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆